Example #1
0
 protected virtual ValueMapper CreateMapper(Type sourceType, Type targetType)
 {
     if (HasOption(MemberMapOptions.Hierarchy))
     {
         ValueMapper mapper;
         if (EnumerableMapper.TryCreate(sourceType, targetType, _container, out mapper))
         {
             return(mapper);
         }
     }
     return(null);
 }
Example #2
0
        internal Action <TSource, TTarget> GetMapAction <TSource, TTarget>()
        {
            Compile();
            ValueMapper mapper;

            if (EnumerableMapper.TryCreate(typeof(TSource), typeof(TTarget), this, out mapper))
            {
                mapper.Compile(_moduleBuilder);
                return((Action <TSource, TTarget>)mapper.CreateDelegate(typeof(TSource), typeof(TTarget), _moduleBuilder));
            }

            var typeMapper = TypeMapper <TSource, TTarget> .GetInstance(this);

            typeMapper.SetReadOnly();
            typeMapper.Compile(_moduleBuilder);
            return(typeMapper.CreateMapper(_moduleBuilder));
        }
Example #3
0
        public static bool TryCreate(Type sourceType, Type targetType, MappingContainer container, out ValueMapper mapper)
        {
            mapper = null;
            Type sourceElementType, targetElementType;

            if (sourceType.IsEnumerable(out sourceElementType) && targetType.IsEnumerable(out targetElementType))
            {
#if NETSTANDARD
                var sourceElementTypeInfo = sourceElementType.GetTypeInfo();
                var targetElementTypeInfo = targetElementType.GetTypeInfo();
#else
                var sourceElementTypeInfo = sourceElementType;
                var targetElementTypeInfo = targetElementType;
#endif
                if (!sourceElementTypeInfo.IsValueType && !sourceElementTypeInfo.IsPrimitive &&
                    !targetElementTypeInfo.IsValueType && !targetElementTypeInfo.IsPrimitive)
                {
                    mapper = new EnumerableMapper(container, sourceElementType, targetElementType);
                    return(true);
                }
            }
            return(false);
        }