/// <summary> /// 复制对象 /// </summary> /// <returns></returns> public new ManyToStructureType Clone() { ManyToStructureType obj = new ManyToStructureType(); obj.Property = Property; obj.ClassName = ClassName; obj.PropertyToColumn = new Collection <StructPropertyMap>(); foreach (StructPropertyMap map in PropertyToColumn) { obj.PropertyToColumn.Add(map.Clone()); } return(obj); }
private static void SetColumnValueFromStruct(DataRow targetRow, object obj, PropertyInfo[] properties, ManyToStructureType structure, Dictionary <string, string> colMaps) { if ((structure.PropertyToColumn == null) || (structure.PropertyToColumn.Count == 0)) { throw new ArgumentNullException(); } object objStruct = GetPropertyValue(obj, properties, structure.Property); if (objStruct == null) { return; } Type objType = objStruct.GetType(); PropertyInfo[] structProps = GetProperties(objType); string trueColumn; object objValue; foreach (StructPropertyMap structMap in structure.PropertyToColumn) { trueColumn = GetTrueColumn(structMap.Column, colMaps); objValue = GetPropertyValue(objStruct, structProps, structMap.Property); if ((!String.IsNullOrEmpty(structMap.ActualProperty)) && (objValue != null)) { objValue = GetPropertyValue(objValue , objValue.GetType().GetProperties() , structMap.ActualProperty); } SetDataColumnValue(targetRow, trueColumn, objValue); } }
private static void SetPropertyValueOfStruct(object obj, PropertyInfo[] properties, DataRow sourceRow, ManyToStructureType structure, Dictionary <string, ColumnToColumn> colMaps) { if ((structure.PropertyToColumn == null) || (structure.PropertyToColumn.Count == 0)) { throw new ArgumentNullException(); } // 取得构造函数的信息,创建实例 Type objType = Type.GetType(EOPNameSpace + structure.ClassName); ConstructorInfo[] ctors = GetConstructors(objType); ParameterInfo[] ctorParameters; object objValue; if (ctors != null) { object[] attrs; foreach (ConstructorInfo ctor in ctors) { attrs = ctor.GetCustomAttributes(false); if (CheckSpecialAttribute(attrs, MethodSpecialKind.DefaultCtor)) { ctorParameters = ctor.GetParameters(); object[] values = new object[structure.PropertyToColumn.Count]; int index = 0; object colValue; for (; index < structure.PropertyToColumn.Count; index++) { if (String.IsNullOrEmpty(structure.PropertyToColumn[index].Column)) { objValue = ConvertObjectValueBaseOnTrueType( structure.PropertyToColumn[index].DefaultValue , ctorParameters[index].ParameterType); } else { colValue = GetTargetColumnValue(sourceRow, structure.PropertyToColumn[index].Column, colMaps); if (colValue == null) { break; } else { objValue = ConvertObjectValueBaseOnTrueType(colValue, ctorParameters[index].ParameterType); } } values[index] = objValue; } if (index == structure.PropertyToColumn.Count) { Object structureObj = ctor.Invoke(values); SetPropertyValue(obj, properties, structureObj, structure.Property); } break; } } } }