Com.Aote.ObjectTools.GeneralObject.CopyDataFrom C# (CSharp) Method

CopyDataFrom() public method

public CopyDataFrom ( GeneralObject go ) : void
go GeneralObject
return void
        public void CopyDataFrom(GeneralObject go)
        {
            //复制实体类型
            if (go.entityType != null)
            {
                EntityType = go.EntityType;
            }
            foreach (string key in go._customPropertyValues.Keys)
            {
                object value = go._customPropertyValues[key];
                //是列表,进行列表复制
                if (value is BaseObjectList)
                {
                    //如果列表不存在,新建列表
                    if (!_customPropertyValues.ContainsKey(key) || _customPropertyValues[key] == null)
                    {
                        ObjectList ol = new ObjectList();
                        SetPropertyValue(key, ol, true);
                    }

                    ObjectList nol = (ObjectList)_customPropertyValues[key];
                    nol.CopyFrom(value as BaseObjectList);


                }
                //是对象,进行对象复制
                else if (value is GeneralObject)
                {
                    GeneralObject newgo = new GeneralObject();
                    newgo.CopyFrom((GeneralObject)value);
                    SetPropertyValue(key, newgo, true);
                }
                //是一般属性,调用设置属性值的过程
                else
                {
                    this.NewGetType();
                    SetPropertyValue(key, value, true);
                }
            }
        }

Usage Example

 //转换列表
 public void TransSave()
 {
     TargetObject.Clear();
     foreach (GeneralObject item in (IList)SourceObject)
     {
         //模板对象
         if (TargetObject.templetObject == null)
         {
             throw new Exception("模板对象不能为空!");
         }
         if (TargetObject.TempObj == null)
         {
             throw new Exception("临时对象不能为空!");
         }
         //将临时对象值赋值为要转换对象
         TargetObject.TempObj.CopyFrom(item);
         //产生新对象
         GeneralObject go = new GeneralObject();
         go.WebClientInfo = TargetObject.templetObject.WebClientInfo;
         go.CopyDataFrom(TargetObject.templetObject);
         TargetObject.Add(go);
     }
     //保存
     TargetObject.Save();
 }