以下代码用于对EDM对象的克隆,不过没克隆到EntityKey我就单独加了一句
using System.Reflection;
public static object ModelClone(object o)
{
Type type = o.GetType();
object obj2 = Activator.CreateInstance(type);
foreach (PropertyInfo info in type.GetProperties())
{
if (info.Name == "EntityKey")
{
info.SetValue(obj2, info.GetValue(o, null), null);
}
if (info.CanWrite && (info.PropertyType.IsValueType || (info.PropertyType == typeof(string))))
{
info.SetValue(obj2, info.GetValue(o, null), null);
}
}
return obj2;
} 能够实现对对象(对象包含的细节为system直接的value)
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/7301869/viewspace-446931/ ,如需转载,请注明出处,否则将追究法律责任。