internal TOut Map <TIn, TOut>(TIn inObj, MapContext mapContext) { var mapDefinition = GetMapDefinition <TIn, TOut>(); var mapper = mapContext.PreserveReferences ? mapDefinition.MapperWithCache : mapDefinition.Mapper; return(mapper(inObj, mapContext)); }
public List <TOut> Map <TIn, TOut>(IEnumerable <TIn> source, bool?preserveReferences = null) { if (source == null) { return(null); } var mapContext = new MapContext(this, preserveReferences ?? _preserveReferences); return(mapContext.MapToList <TIn, TOut>(source)); }
internal object Map(object inObj, Type outType, MapContext mapContext) { if (inObj == null) { return(null); } var inType = inObj.GetType(); return(Map(inObj, mapContext, GetMapDefinition(inType, outType))); }
public TOut Map <TOut>(object inObj, bool?preserveReferences = null) { if (inObj == null) { return(default(TOut)); } var mapContext = new MapContext(this, preserveReferences ?? _preserveReferences); return((TOut)Map(inObj, typeof(TOut), mapContext)); }
public List <object> Map(IEnumerable <object> source, bool?preserveReferences = null) { if (source == null) { return(null); } var retVal = new List <object>(); var mapContext = new MapContext(this, preserveReferences ?? _preserveReferences); foreach (var inObj in source) { retVal.Add(Map(inObj, mapContext)); } return(retVal); }
internal object Map(object inObj, MapContext mapContext) { if (inObj == null) { return(null); } var inType = inObj.GetType(); var kvpMap = _mapDefinitions.FirstOrDefault(kvp => kvp.Value.InType == inType); if (!Equals(kvpMap, default(KeyValuePair <int, IMapDefinition>))) { return(Map(inObj, mapContext, kvpMap.Value)); } throw new InvalidOperationException($"Map type cannot be found for {inType.Name}"); }
public object Map(object inObj, bool?preserveReferences = null) { if (inObj == null) { return(null); } var mapContext = new MapContext(this, preserveReferences ?? _preserveReferences); var inType = inObj.GetType(); var kvpMap = _mapDefinitions.FirstOrDefault(kvp => kvp.Value.InType == inType); if (!Equals(kvpMap, default(KeyValuePair <int, IMapDefinition>))) { return(Map(inObj, mapContext, kvpMap.Value)); } throw new InvalidOperationException($"Map type cannot be found for {inType.Name}"); }
public object Map(object inObj, bool?preserveReferences = null) { if (inObj == null) { return(null); } var mapContext = new MapContext(this, preserveReferences ?? _preserveReferences); var inType = inObj.GetType(); foreach (var kvp in _mapDefinitions) { if (kvp.Value.InType == inType) { return(Map(inObj, mapContext, kvp.Value)); } } throw new InvalidOperationException($"Map type cannot be found for {inType.Name}"); }
public Dictionary <TOutKey, TOutValue> Map <TInKey, TInValue, TOutKey, TOutValue>(IDictionary <TInKey, TInValue> source, bool?preserveReferences = null) { var mapContext = new MapContext(this, preserveReferences ?? _preserveReferences); return(mapContext.MapToDictionary <TInKey, TInValue, TOutKey, TOutValue>(source)); }
internal object Map(object inObj, MapContext mapContext, IMapDefinition mapDefinition) { var mapper = mapContext.PreserveReferences ? mapDefinition.MapperWithCache : mapDefinition.Mapper; return(mapper.DynamicInvoke(inObj, mapContext)); }