zoukankan      html  css  js  c++  java
  • DTO的深度克隆实现

                   

     /// <summary>
            
    /// 克隆方法
            
    /// </summary>
            
    /// <returns></returns>
            public object Clone()
            {
                try
                {

                    Type type = this.GetType();

                    VoucherDTO vd = (VoucherDTO)Activator.CreateInstance(type);

                    PropertyInfo[] pilist = type.GetProperties();

                    foreach (PropertyInfo item in pilist)
                    {
                        PropertyInfo pi = this.GetType().GetProperty(item.Name);

                        if (pi != null)
                        {
                            object value = pi.GetValue(thisnull);

                            item.SetValue(vd, value, null);
                        }
                    }

                    vd.Details = new List<VoucherDTO>();

                    return vd;
                }
                catch (Exception ex)
                {
                    throw new Exception("克隆方法出现异常!", ex);

                }
            }
  • 相关阅读:
    第13章 TCP/IP和网络编程
    实验二测试
    实验四 Web服务器1socket编程
    thread同步测试
    团队作业(五):冲刺总结——第四天
    111
    递归和数学归纳法
    Nodejs中cluster模块的多进程共享数据问题
    JavaScript写类方式(一)——工厂方式
    JavaScript中的shift()和pop()函数
  • 原文地址:https://www.cnblogs.com/ronphy/p/2443460.html
Copyright © 2011-2022 走看看