添加了数据库相关了类,和枚举类型相关的类,并且将枚举类型绑定到前段

This commit is contained in:
2025-06-20 18:53:29 +08:00
parent 5dfce624c4
commit 908dc60439
29 changed files with 437 additions and 151 deletions

View File

@@ -25,4 +25,27 @@ public static class ObjectExtensions
}
}
}
/// <summary>
/// 创建一个泛型对象将source对象上的所有属性的值都转换到新创建对象上
/// </summary>
/// <param name="source"></param>
/// <param name="target"></param>
/// <typeparam name="T"></typeparam>
public static void NewTo<T>(this Object source ) where T : new()
{
T target = new T();
var sourceType = source.GetType();
var targetType = target.GetType();
var sourceProperties = sourceType.GetProperties();
foreach (PropertyInfo sourceProperty in sourceProperties)
{
PropertyInfo targetProperty = targetType.GetProperty(sourceProperty.Name);
if (targetProperty!= null && targetProperty.CanWrite && sourceProperty.CanRead && targetProperty.PropertyType == sourceProperty.PropertyType)
{
object value = sourceProperty.GetValue(source, null);
targetProperty.SetValue(target, value, null);
}
}
}
}