123456789101112131415161718192021222324252627282930313233343536373839404142 |
- using System.Reflection;
- using Extensions;
- namespace Infrastructure
- {
- public static class EntityExtension
- {
- public static TSource ToCreate<TSource>(this TSource source, HttpContext? context = null)
- {
- var types = source?.GetType();
- if (types == null || context == null) return source;
- BindingFlags flag = BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance;
-
-
-
-
-
-
- types.GetProperty("CreateDate", flag)?.SetValue(source, DateTime.Now, null);
- types.GetProperty("UpdateDate", flag)?.SetValue(source, DateTime.Now, null);
- return source;
- }
- public static TSource ToUpdate<TSource>(this TSource source, HttpContext? context = null)
- {
- var types = source?.GetType();
- if (types == null || context == null) return source;
- BindingFlags flag = BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance;
-
-
-
-
- types.GetProperty("UpdateDate", flag)?.SetValue(source, DateTime.Now, null);
- return source;
- }
- }
- }
|