public override void Map(ref object from, ref object to) { if (from == null) { return; } if (isFromDataTable) { new DataReaderMapper(_Info.To).Map(ref from, ref to); } else { DataTable dt = to as DataTable; if (dt == null) { dt = ObjectCreator.Create(_Info.To) as DataTable; } if (string.IsNullOrEmpty(dt.TableName)) { dt.TableName = elementType.Name; } PopulateColumns(dt); FillDataTable(from as IEnumerable, dt); to = dt; } }
public override void Map(ref object from, ref object to) { if (from == null) { return; } if (to == null) { to = ObjectCreator.Create(_Info.To); } var newFrom = isFromListSource ? (from as IListSource).GetList() : from; var fromType = newFrom.GetType(); var tmpTo = isToListSource ? (to as IListSource).GetList() as object: to; new CollectionMapper(_Info.From, tmpTo.GetType()).Map(ref from, ref tmpTo); }
public override void Map(ref object from, ref object to) { if (to == null) { to = ObjectCreator.Create(_Info.To); } if (_Info.From.IsDictionaryType()) { var dicType = _Info.From.GetGenericDictionaryType(); var keyType = dicType.GetGenericArguments()[0]; var valueType = dicType.GetGenericArguments()[1]; if (keyType == Types.String) { if (valueType == Types.String) { new DictionaryOfStringAndString { State = this.State } }
public override void Map(ref object from, ref object to) { if (from == null) { return; } var sourceEnumerableValue = (IEnumerable)from; var sourceInfo = new DictionaryInfo(); var destInfo = new DictionaryInfo(); GetDictionaryInfo(fromType, ref sourceInfo); GetDictionaryInfo(toType, ref destInfo); if (to == null) { if (destInfo.IsGeneric) { to = ObjectCreator.Create(typeof(Dictionary <,>).MakeGenericType(destInfo.Key, destInfo.Value)); } else { to = ObjectCreator.Create(destInfo.Type); } } var addMethod = destInfo.Type.GetMethod("Add", new Type[] { destInfo.Key, destInfo.Value }).GetProc(); var getKey = sourceInfo.Kvp.GetProperty("Key").GetGetter(); var getValue = sourceInfo.Kvp.GetProperty("Value").GetGetter(); var kvpEquals = sourceInfo.Kvp == destInfo.Kvp; var keyEquals = kvpEquals ? true : (sourceInfo.Key == destInfo.Key || destInfo.Key.IsAssignableFrom(sourceInfo.Key)); var valueEquals = kvpEquals ? true : (sourceInfo.Value == destInfo.Value || destInfo.Value.IsAssignableFrom(sourceInfo.Value)); foreach (var item in sourceEnumerableValue) { var key = getKey(item); var value = getValue(item); var dstKey = keyEquals ? key : Mapper.Map(key, Types.Object, destInfo.Key); var dstValue = valueEquals ? value : Mapper.Map(value, Types.Object, destInfo.Value); addMethod(to, dstKey, dstValue); } }