public override void FillData(object srcInstance, object destInstance) { var srcValue = _srcPropertyInfo.GetValue(srcInstance, null); if (srcValue == null) { _destPropertyInfo.SetValue(destInstance, null, null); return; } var destValue = _destPropertyInfo.GetValue(destInstance, null); var srcList = SourceArrayList.Create(srcValue); if (srcList == null) { throw new Exception("[" + srcValue + "] of the class[" + srcInstance + "] should have the IList or IListReadOnly interface"); } if (destValue == null) { destValue = _destArrayConstructor.Invoke(srcList); _destPropertyInfo.SetValue(destInstance, destValue, null); } var destList = destValue as IList; if (destList == null) { throw new Exception("[" + destValue + "] of the class[" + destInstance + "] should have the IList interface"); } if (destList.Count != srcList.Count) { if (_destArrayConstructor.CahBeSynched) { _destArrayConstructor.SynchRecordsCount(srcList, destList); } else { destValue = _destArrayConstructor.Invoke(srcList); _destPropertyInfo.SetValue(destInstance, destValue, null); } } if (_elementTypeMap == null) { FillSimpleData(srcList, destList); } else { FillReferenceData(srcList, destList); } }
public override object CreateDestInstance(object srcInstance) { var srcList = SourceArrayList.Create(srcInstance); if (srcList == null) { throw new ExceptionOfMapping("Somehow appears that the class " + srcInstance.GetType() + " without IList interface tried to map to the array class (ArrayTypeMapper.CreateDestInstance)"); } var destList = _destArrayConstructor.Invoke(srcList); SynchInstances(srcInstance, destList); return(destList); }
public override void SynchInstances(object srcInstance, object destInstance) { var srcList = SourceArrayList.Create(srcInstance); if (srcList == null) { throw new ExceptionOfMapping("Somehow appears that the class " + srcInstance.GetType() + " without IList interface tried to map to the array class (ArrayTypeMapper.SynchInstances)"); } var destList = destInstance == null?_destArrayConstructor.Invoke(srcList) : destInstance as IList; if (destList == null) { throw new ExceptionOfMapping("Somehow appears that the dest class for source class" + srcInstance.GetType() + " without IList interface tried to map to the array class (ArrayTypeMapper.SynchInstances)"); } var i = 0; foreach (var itm in srcList) { destList[i++] = _arrayItemMap.CreateDestInstance(itm); } }