Exemplo n.º 1
0
        /// <summary>
        /// All these map puns are giving me a headache.
        /// </summary>
        private static void Mapptivate(Mapptribute mapsToAttribute, Type sourceType, Type destinationType, IMapperConfiguration mapperConfiguration)
        {
            var configureMappingGenericMethod = GetConfigureMappingGenericMethod(mapsToAttribute, sourceType, destinationType);

            if (configureMappingGenericMethod == null)
            {
                var map = mapperConfiguration == null?Mapper.CreateMap(sourceType, destinationType, mapsToAttribute.MemberList) : mapperConfiguration.CreateMap(sourceType, destinationType, mapsToAttribute.MemberList);

                mapsToAttribute.ConfigureMapping(map);
            }
            else
            {
                var createMapMethod = mapperConfiguration == null?GenericCreateMapStaticApi.MakeGenericMethod(sourceType, destinationType) : GenericCreateMap.MakeGenericMethod(sourceType, destinationType);

                var map = createMapMethod.Invoke(mapperConfiguration ?? null, new object[] {});
                configureMappingGenericMethod.Invoke(mapsToAttribute, new[] { map });
            }

            if (mapsToAttribute.ReverseMap)
            {
                if (mapperConfiguration == null)
                {
                    Mapper.CreateMap(destinationType, sourceType);
                }
                else
                {
                    mapperConfiguration.CreateMap(destinationType, sourceType);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// All these map puns are giving me a headache.
        /// </summary>
        private static void Mapptivate(Mapptribute mapsToAttribute, Type sourceType, Type targetType, IMapperConfigurationExpression mapperConfiguration, Type[] types, bool reverseMap)
        {
            var configureMappingGenericMethod = GetConfigureMappingGenericMethod(mapsToAttribute, sourceType, targetType);
            var mappedProperties  = GetMappedProperties(types, sourceType, targetType);
            var mappingExpression = MapTypes(sourceType, targetType, mappedProperties, mapperConfiguration);

            configureMappingGenericMethod?.Invoke(mapsToAttribute, new[] { mappingExpression });

            if (reverseMap)
            {
                Mapptivate(mapsToAttribute, targetType, sourceType, mapperConfiguration, types, false);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// All these map puns are giving me a headache.
        /// </summary>
        private static void Mapptivate(Mapptribute mapsToAttribute, Type sourceType, Type destinationType)
        {
            var configureMappingGenericMethod = GetConfigureMappingGenericMethod(mapsToAttribute, sourceType, destinationType);

            if (configureMappingGenericMethod == null)
            {
                var map = Mapper.CreateMap(sourceType, destinationType);
                mapsToAttribute.ConfigureMapping(map);
            }
            else
            {
                var createMapMethod = GenericCreateMap.MakeGenericMethod(sourceType, destinationType);
                var map             = createMapMethod.Invoke(null, new object[] {});
                configureMappingGenericMethod.Invoke(mapsToAttribute, new[] { map });
            }

            if (mapsToAttribute.ReverseMap)
            {
                Mapper.CreateMap(destinationType, sourceType);
            }
        }
Exemplo n.º 4
0
 private static MethodInfo GetConfigureMappingGenericMethod(Mapptribute mapsToAttribute, Type sourceType, Type destinationType)
 {
     return(mapsToAttribute.GetType()
            .GetMethod(nameof(Mapptribute.ConfigureMapping), new[] { typeof(IMappingExpression <,>)
                                                                     .MakeGenericType(sourceType, destinationType) }));
 }
Exemplo n.º 5
0
 private static MethodInfo GetConfigureMappingGenericMethod(Mapptribute mapsToAttribute, Type sourceType, Type targetType)
 {
     return(mapsToAttribute.GetType()
            .GetMethod("ConfigureMapping",
                       new[] { typeof(IMappingExpression <,>).MakeGenericType(sourceType, targetType) }));
 }