public static T Clone(T src)
{
T val = new T();
PropertyInfo[] properties = val.GetType().GetProperties();
foreach (PropertyInfo propertyInfo in properties)
{
PropertyInfo[] properties2 = src.GetType().GetProperties();
foreach (PropertyInfo propertyInfo2 in properties2)
{
if (propertyInfo.Name == propertyInfo2.Name && propertyInfo.PropertyType == propertyInfo2.PropertyType && propertyInfo.Name != "Error" && propertyInfo.Name != "Item")
{
propertyInfo.SetValue(val, propertyInfo2.GetValue(src, null), null);
}
}
}
return val;
}
C#反射复制
最新推荐文章于 2025-01-20 15:36:25 发布