1#
方法很容易创建实例然后枚举出属性名和属性值再赋值到另一相同类的对象中

完美从detail对象赋值一个到obj对象

自动获取对象中类型的办法是参考:http://blog.csdn.net/xiaohan2826/article/details/8536074
  1. Type type = typeof(CustomerDetail);

  2.             object obj = Activator.CreateInstance(type);

  3.             PropertyInfo[] props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);

  4.             foreach (PropertyInfo p in props)

  5.             {

  6.                 string elementName = p.Name.Substring(0);

  7.                 object elementValue = p.GetValue(detail, null);

  8.                 var property = obj.GetType().GetProperty(elementName);

  9.                 p.SetValue(obj, Convert.ChangeType(elementValue, property.PropertyType), null);

  10.             }

复制代码