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);

                }
            }
  • 相关阅读:
    Notification的使用
    Spring面向切面之AOP深入探讨
    使用注解配置Spring框架自动代理通知
    回顾Spring框架
    Spring利器之包扫描器
    Spring 核心概念以及入门教程
    Struts 2之动态方法调用,不会的赶紧来
    Struts2之过滤器和拦截器的区别
    Struts 2开讲了!!!
    Mybatis开篇以及配置教程
  • 原文地址:https://www.cnblogs.com/ronphy/p/2443460.html
Copyright © 2011-2022 走看看