ITPub博客

首页 > Linux操作系统 > Linux操作系统 > .net对象真克隆

.net对象真克隆

原创 Linux操作系统 作者:lcjbest 时间:2008-09-12 23:38:39 0 删除 编辑

以下代码用于对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/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 起步(一)
请登录后发表评论 登录
全部评论

注册时间:2008-08-23

  • 博文量
    11
  • 访问量
    7490