Example #1
0
        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));
        }
Example #2
0
        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));
        }
Example #3
0
        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)));
        }
Example #4
0
        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));
        }
Example #5
0
        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);
        }
Example #6
0
        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}");
        }
Example #7
0
        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}");
        }
Example #8
0
        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}");
        }
Example #9
0
        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));
        }
Example #10
0
        internal object Map(object inObj, MapContext mapContext, IMapDefinition mapDefinition)
        {
            var mapper = mapContext.PreserveReferences ? mapDefinition.MapperWithCache : mapDefinition.Mapper;

            return(mapper.DynamicInvoke(inObj, mapContext));
        }