Exemplo n.º 1
0
        private bool MapDestinationCtorToSource(TypeMap typeMap, ConstructorInfo destCtor, TypeInfo sourceTypeInfo,
                                                IMappingOptions options)
        {
            var parameters = new List<ConstructorParameterMap>();
            var ctorParameters = destCtor.GetParameters();

            if (ctorParameters.Length == 0 || !options.ConstructorMappingEnabled)
                return false;

            foreach (var parameter in ctorParameters)
            {
                var members = new LinkedList<MemberInfo>();

                if (!MapDestinationPropertyToSource(members, sourceTypeInfo, parameter.Name, options))
                    return false;

                var resolvers = members.Select(mi => mi.ToMemberGetter());

                var param = new ConstructorParameterMap(parameter, resolvers.ToArray());

                parameters.Add(param);
            }

            typeMap.AddConstructorMap(destCtor, parameters);

            return true;
        }
Exemplo n.º 2
0
        public TypeMap CreateTypeMap(Type sourceType, Type destinationType, IMappingOptions options,
            MemberList memberList)
        {
            var sourceTypeInfo = GetTypeInfo(sourceType, options);
            var destTypeInfo = GetTypeInfo(destinationType, options.ShouldMapProperty, options.ShouldMapField, new MethodInfo[0]);

            var typeMap = new TypeMap(sourceTypeInfo, destTypeInfo, memberList);

            foreach (var destProperty in destTypeInfo.PublicWriteAccessors)
            {
                var members = new LinkedList<MemberInfo>();

                if (MapDestinationPropertyToSource(members, sourceTypeInfo, destProperty.Name, options))
                {
                    var resolvers = members.Select(mi => mi.ToMemberGetter());
                    var destPropertyAccessor = destProperty.ToMemberAccessor();

                    typeMap.AddPropertyMap(destPropertyAccessor, resolvers.Cast<IValueResolver>());
                }
            }
            if (!destinationType.IsAbstract() && destinationType.IsClass())
            {
                foreach (var destCtor in destTypeInfo.Constructors.OrderByDescending(ci => ci.GetParameters().Length))
                {
                    if (MapDestinationCtorToSource(typeMap, destCtor, sourceTypeInfo, options))
                    {
                        break;
                    }
                }
            }
            return typeMap;
        }
Exemplo n.º 3
0
        public TypeMap CreateTypeMap(Type sourceType, Type destinationType, IProfileConfiguration options, MemberList memberList)
        {
            var sourceTypeInfo = GetTypeInfo(sourceType, options);
            var destTypeInfo = GetTypeInfo(destinationType, options);

            var typeMap = new TypeMap(sourceTypeInfo, destTypeInfo, memberList, options.ProfileName);

            foreach (var destProperty in destTypeInfo.PublicWriteAccessors)
            {
                var resolvers = new LinkedList<IValueResolver>();

                if (MapDestinationPropertyToSource(options, sourceTypeInfo, destProperty.GetMemberType(), destProperty.Name, resolvers))
                {
                    var destPropertyAccessor = destProperty.ToMemberAccessor();

                    typeMap.AddPropertyMap(destPropertyAccessor, resolvers);
                }
            }
            if (!destinationType.IsAbstract() && destinationType.IsClass())
            {
                foreach (var destCtor in destTypeInfo.Constructors.OrderByDescending(ci => ci.GetParameters().Length))
                {
                    if (MapDestinationCtorToSource(typeMap, destCtor, sourceTypeInfo, options))
                    {
                        break;
                    }
                }
            }
            return typeMap;
        }
Exemplo n.º 4
0
        public TypeMap CreateTypeMap(Type sourceType, Type destinationType, IMappingOptions options)
        {
            var sourceTypeInfo = GetTypeInfo(sourceType);
            var destTypeInfo = GetTypeInfo(destinationType);

            var typeMap = new TypeMap(sourceTypeInfo, destTypeInfo);

            foreach (var destProperty in destTypeInfo.GetPublicWriteAccessors())
            {
                var members = new LinkedList<MemberInfo>();

                if (MapDestinationPropertyToSource(members, sourceTypeInfo, destProperty.Name, options))
                {
                    var resolvers = members.Select(mi => mi.ToMemberGetter());
                    var destPropertyAccessor = destProperty.ToMemberAccessor();
            #if !SILVERLIGHT
                    typeMap.AddPropertyMap(destPropertyAccessor, resolvers);
            #else
                    typeMap.AddPropertyMap(destPropertyAccessor, resolvers.Cast<IValueResolver>());
            #endif
                }
            }
            if (!destinationType.IsAbstract && destinationType.IsClass)
            {
                foreach (var destCtor in destTypeInfo.GetConstructors().OrderByDescending(ci => ci.GetParameters().Length))
                {
                    if (MapDestinationCtorToSource(typeMap, destCtor, sourceTypeInfo, options))
                    {
                        break;
                    }
                }
            }
            return typeMap;
        }
Exemplo n.º 5
0
        private bool MapDestinationCtorToSource(TypeMap typeMap, ConstructorInfo destCtor, TypeDetails sourceTypeInfo, IProfileConfiguration options)
        {
            var parameters = new List<ConstructorParameterMap>();
            var ctorParameters = destCtor.GetParameters();

            if (ctorParameters.Length == 0 || !options.ConstructorMappingEnabled)
                return false;

            foreach (var parameter in ctorParameters)
            {
                var resolvers = new LinkedList<IValueResolver>();

                var canResolve = MapDestinationPropertyToSource(options, sourceTypeInfo, parameter.GetType(), parameter.Name, resolvers);
                if(!canResolve && parameter.HasDefaultValue)
                {
                    canResolve = true;
                }

                var param = new ConstructorParameterMap(parameter, resolvers.ToArray(), canResolve);

                parameters.Add(param);
            }

            typeMap.AddConstructorMap(destCtor, parameters);

            return true;
        }
Exemplo n.º 6
0
        public TypeMap CreateTypeMap(Type sourceType, Type destinationType, ProfileMap options, MemberList memberList)
        {
            var sourceTypeInfo = options.CreateTypeDetails(sourceType);
            var destTypeInfo = options.CreateTypeDetails(destinationType);

            var typeMap = new TypeMap(sourceTypeInfo, destTypeInfo, memberList, options);

            foreach (var destProperty in destTypeInfo.PublicWriteAccessors)
            {
                var resolvers = new LinkedList<MemberInfo>();

                if (MapDestinationPropertyToSource(options, sourceTypeInfo, destProperty.DeclaringType, destProperty.GetMemberType(), destProperty.Name, resolvers))
                {
                    typeMap.AddPropertyMap(destProperty, resolvers);
                }
            }
            if (!destinationType.IsAbstract() && destinationType.IsClass())
            {
                foreach (var destCtor in destTypeInfo.Constructors.OrderByDescending(ci => ci.GetParameters().Length))
                {
                    if (MapDestinationCtorToSource(typeMap, destCtor, sourceTypeInfo, options))
                    {
                        break;
                    }
                }
            }
            return typeMap;
        }
Exemplo n.º 7
0
        private bool MapDestinationCtorToSource(TypeMap typeMap, ConstructorInfo destCtor, TypeDetails sourceTypeInfo, ProfileMap options)
        {
            var ctorParameters = destCtor.GetParameters();

            if (ctorParameters.Length == 0 || !options.ConstructorMappingEnabled)
                return false;

            var ctorMap = new ConstructorMap(destCtor, typeMap);

            foreach (var parameter in ctorParameters)
            {
                var resolvers = new LinkedList<MemberInfo>();

                var canResolve = MapDestinationPropertyToSource(options, sourceTypeInfo, destCtor.DeclaringType, parameter.GetType(), parameter.Name, resolvers);
                if(!canResolve && parameter.HasDefaultValue)
                {
                    canResolve = true;
                }

                ctorMap.AddParameter(parameter, resolvers.ToArray(), canResolve);
            }

            typeMap.ConstructorMap = ctorMap;

            return true;
        }
        public AutoMapperConfigurationException(TypeMap typeMap, string[] unmappedPropertyNames)
            : base(string.Format(
					"The following {3} properties on {0} are not mapped: \n\t{2}\nAdd a custom mapping expression, ignore, or rename the property on {1}.",
					typeMap.DestinationType.FullName, typeMap.SourceType.FullName, string.Join("\n\t", unmappedPropertyNames),
					unmappedPropertyNames.Length))
        {
        }
Exemplo n.º 9
0
 private void DryRunTypeMap(ICollection<TypeMap> typeMapsChecked, TypePair types, TypeMap typeMap, ResolutionContext context)
 {
     if (typeMap != null)
     {
         typeMapsChecked.Add(typeMap);
         if(typeMap.CustomMapper != null || typeMap.TypeConverterType != null)
         {
             return;
         }
         CheckPropertyMaps(typeMapsChecked, typeMap, context);
     }
     else
     {
         var mapperToUse = _config.GetMappers().FirstOrDefault(mapper => mapper.IsMatch(types));
         if (mapperToUse == null && types.SourceType.IsNullableType())
         {
             var nullableTypes = new TypePair(Nullable.GetUnderlyingType(types.SourceType),
                 types.DestinationType);
             mapperToUse = _config.GetMappers().FirstOrDefault(mapper => mapper.IsMatch(nullableTypes));
         }
         if (mapperToUse == null)
         {
             throw new AutoMapperConfigurationException(types);
         }
         if (mapperToUse is ArrayMapper || mapperToUse is EnumerableMapper || mapperToUse is CollectionMapper)
         {
             CheckElementMaps(typeMapsChecked, types, context);
         }
     }
 }
 public static IEnumerable<MapVisual> X(TypeMap map)
 {
     foreach (var propertyMap in map.GetPropertyMaps())
     {
         yield return new MapVisual
         {
             SourceSystem = extractSystem(propertyMap.SourceMember),
             SourceValue = getValue(propertyMap.SourceMember),
             TargetSystem = extractSystem(propertyMap.DestinationProperty),
             TargetValue = propertyMap.DestinationProperty.Name
         };
     }
 }
Exemplo n.º 11
0
        public TypeMap CreateTypeMap(Type sourceType, Type destinationType, IMappingOptions options)
        {
            var sourceTypeInfo = GetTypeInfo(sourceType);
            var destTypeInfo = GetTypeInfo(destinationType);

            var typeMap = new TypeMap(sourceTypeInfo, destTypeInfo);

            foreach (var destProperty in destTypeInfo.GetPublicWriteAccessors())
            {
                var members = new LinkedList<MemberInfo>();

                if (MapDestinationPropertyToSource(members, sourceTypeInfo, destProperty.Name, options))
                {
                    var resolvers = members.Select(mi => mi.ToMemberGetter()).Cast<IValueResolver>();
                    var destPropertyAccessor = destProperty.ToMemberAccessor();
                    typeMap.AddPropertyMap(destPropertyAccessor, resolvers);
                }
            }
            return typeMap;
        }
Exemplo n.º 12
0
 public MappingExpression(TypeMap typeMap, Func <Type, object> typeConverterCtor)
 {
     _typeMap           = typeMap;
     _typeConverterCtor = typeConverterCtor;
 }
Exemplo n.º 13
0
        private void CheckPropertyMaps(ICollection<TypeMap> typeMapsChecked, TypeMap typeMap, ResolutionContext context)
        {
            foreach (var propertyMap in typeMap.GetPropertyMaps())
            {
                if (propertyMap.Ignored) continue;

                var sourceType = propertyMap.SourceType;

                if (sourceType == null) continue;

                // when we don't know what the source type is, bail
                if (sourceType.IsGenericParameter || sourceType == typeof (object))
                    return;

                var destinationType = propertyMap.DestinationProperty.GetMemberType();
                var memberTypeMap = _config.ResolveTypeMap(sourceType,
                    destinationType);

                if (typeMapsChecked.Any(tm => Equals(tm, memberTypeMap)))
                    continue;

                DryRunTypeMap(typeMapsChecked, new TypePair(sourceType, destinationType), memberTypeMap, context);
            }
        }
Exemplo n.º 14
0
        private IMappingExpression <TSource, TDestination> CreateMappingExpression <TSource, TDestination>(TypeMap typeMap)
        {
            var mappingExp = new MappingExpression <TSource, TDestination>(typeMap, _serviceCtor, this);
            var type       = (typeMap.ConfiguredMemberList == MemberList.Destination) ? typeof(TDestination) : typeof(TSource);

            return(Ignore(mappingExp, type));
        }
Exemplo n.º 15
0
        public PathMap FindOrCreatePathMapFor(LambdaExpression destinationExpression, MemberPath path, TypeMap typeMap)
        {
            var pathMap = _pathMaps.SingleOrDefault(p => p.MemberPath == path);

            if (pathMap == null)
            {
                pathMap = new PathMap(destinationExpression, path, typeMap);
                _pathMaps.Add(pathMap);
            }
            return(pathMap);
        }
Exemplo n.º 16
0
 public IncludedMember(TypeMap typeMap, LambdaExpression memberExpression) : this(typeMap, memberExpression,
                                                                                  Variable(memberExpression.Body.Type, string.Join("", memberExpression.GetMembersChain().Select(m => m.Name))), memberExpression)
 {
 }
Exemplo n.º 17
0
 private void ApplyMemberMaps(TypeMap mainMap, IConfigurationProvider configurationProvider)
 {
     AddMemberMaps(mainMap.IncludedMembers, mainMap, configurationProvider);
     AddMemberMaps(mainMap.GetUntypedIncludedMembers(), mainMap, configurationProvider);
 }
Exemplo n.º 18
0
 protected void OnTypeMapCreated(TypeMap typeMap)
 {
     TypeMapCreated?.Invoke(this, new TypeMapCreatedEventArgs(typeMap));
 }
Exemplo n.º 19
0
 internal void DecrementTypeDepth(TypeMap typeMap) => TypeDepth[typeMap.Types]--;
 public TypeMapConfigErrors(TypeMap typeMap, string[] unmappedPropertyNames, bool canConstruct)
 {
     TypeMap = typeMap;
     UnmappedPropertyNames = unmappedPropertyNames;
     CanConstruct          = canConstruct;
 }
Exemplo n.º 21
0
 internal void ValidateMap(TypeMap typeMap)
 => ConfigurationProvider.AssertConfigurationIsValid(typeMap);
Exemplo n.º 22
0
 internal void IncrementTypeDepth(TypeMap typeMap) => TypeDepth[typeMap.Types]++;
Exemplo n.º 23
0
 public PropertyMap(PropertyMap includedMemberMap, TypeMap typeMap, LambdaExpression expression)
     : this(includedMemberMap, typeMap) => ApplyIncludedMemberMap(includedMemberMap, expression);
Exemplo n.º 24
0
 public void RegisterTypeMap(TypeMap typeMap) => _typeMaps[typeMap.Types] = typeMap;
Exemplo n.º 25
0
        private IMappingExpression CreateMappingExpression(TypeMap typeMap, Type destinationType)
        {
            var mappingExp = new MappingExpression(typeMap, _serviceCtor, this);

            return((IMappingExpression)Ignore(mappingExp, destinationType));
        }
Exemplo n.º 26
0
 public void InheritTypes(TypeMap inheritedTypeMap)
 {
     foreach (var includedDerivedType in inheritedTypeMap._includedDerivedTypes
         .Where(includedDerivedType => !_includedDerivedTypes.Contains(includedDerivedType)))
     {
         _includedDerivedTypes.Add(includedDerivedType);
     }
 }
Exemplo n.º 27
0
        private void ApplyInheritedTypeMap(TypeMap inheritedTypeMap)
        {
            foreach (var inheritedMappedProperty in inheritedTypeMap.GetPropertyMaps().Where(m => m.IsMapped()))
            {
                var conventionPropertyMap = GetPropertyMaps()
                    .SingleOrDefault(m =>
                        m.DestinationProperty.Name == inheritedMappedProperty.DestinationProperty.Name);

                if (conventionPropertyMap != null)
                {
                    conventionPropertyMap.ApplyInheritedPropertyMap(inheritedMappedProperty);
                }
                else
                {
                    var propertyMap = new PropertyMap(inheritedMappedProperty, this);

                    _inheritedMaps.Add(propertyMap);
                }
            }

            //Include BeforeMap
            foreach (var beforeMapAction in inheritedTypeMap._beforeMapActions)
            {
                AddBeforeMapAction(beforeMapAction);
            }
            //Include AfterMap
            foreach (var afterMapAction in inheritedTypeMap._afterMapActions)
            {
                AddAfterMapAction(afterMapAction);
            }
        }
Exemplo n.º 28
0
 public ConstructorMap(ConstructorInfo ctor, TypeMap typeMap)
 {
     Ctor = ctor;
     TypeMap = typeMap;
 }
Exemplo n.º 29
0
 private static void ApplyBaseMaps(TypeMapRegistry typeMapRegistry, TypeMap derivedMap, TypeMap currentMap)
 {
     foreach (var baseMap in currentMap.IncludedBaseTypes.Select(typeMapRegistry.GetTypeMap).Where(baseMap => baseMap != null))
     {
         baseMap.IncludeDerivedTypes(currentMap.SourceType, currentMap.DestinationType);
         derivedMap.ApplyInheritedMap(baseMap);
         ApplyBaseMaps(typeMapRegistry, derivedMap, baseMap);
     }
 }
Exemplo n.º 30
0
        private void DryRunTypeMap(ICollection <TypeMap> typeMapsChecked, ResolutionContext context)
        {
            if (context.TypeMap != null)
            {
                typeMapsChecked.Add(context.TypeMap);
            }

            var mapperToUse = GetMappers().FirstOrDefault(mapper => mapper.IsMatch(context));

            if (mapperToUse == null && context.SourceType.IsNullableType())
            {
                var nullableContext = context.CreateValueContext(null, Nullable.GetUnderlyingType(context.SourceType));

                mapperToUse = GetMappers().FirstOrDefault(mapper => mapper.IsMatch(nullableContext));
            }

            if (mapperToUse == null)
            {
                throw new AutoMapperConfigurationException(context);
            }

            if (mapperToUse is TypeMapMapper)
            {
                foreach (var propertyMap in context.TypeMap.GetPropertyMaps())
                {
                    if (!propertyMap.IsIgnored())
                    {
                        var lastResolver =
                            propertyMap.GetSourceValueResolvers().OfType <IMemberResolver>().LastOrDefault();

                        if (lastResolver != null)
                        {
                            var sourceType      = lastResolver.MemberType;
                            var destinationType = propertyMap.DestinationProperty.MemberType;
                            var memberTypeMap   = ((IConfigurationProvider)this).ResolveTypeMap(sourceType,
                                                                                                destinationType);

                            if (typeMapsChecked.Any(typeMap => Equals(typeMap, memberTypeMap)))
                            {
                                continue;
                            }

                            var memberContext = context.CreateMemberContext(memberTypeMap, null, null, sourceType,
                                                                            propertyMap);

                            DryRunTypeMap(typeMapsChecked, memberContext);
                        }
                    }
                }
            }
            else if (mapperToUse is ArrayMapper || mapperToUse is EnumerableMapper || mapperToUse is CollectionMapper)
            {
                Type    sourceElementType = TypeHelper.GetElementType(context.SourceType);
                Type    destElementType   = TypeHelper.GetElementType(context.DestinationType);
                TypeMap itemTypeMap       = ((IConfigurationProvider)this).ResolveTypeMap(sourceElementType, destElementType);

                if (typeMapsChecked.Any(typeMap => Equals(typeMap, itemTypeMap)))
                {
                    return;
                }

                var memberContext = context.CreateElementContext(itemTypeMap, null, sourceElementType, destElementType,
                                                                 0);

                DryRunTypeMap(typeMapsChecked, memberContext);
            }
        }
Exemplo n.º 31
0
 public ValidationContext(TypePair types, PropertyMap propertyMap, TypeMap typeMap) : this(types, propertyMap, null, typeMap)
 {
 }
Exemplo n.º 32
0
 public PathMap(LambdaExpression destinationExpression, MemberPath memberPath, TypeMap typeMap)
 {
     MemberPath            = memberPath;
     TypeMap               = typeMap;
     DestinationExpression = destinationExpression;
 }
Exemplo n.º 33
0
        private static LambdaExpression GenerateTypeMapExpression(MapRequest mapRequest, TypeMap typeMap)
        {
            var mapExpression               = typeMap.MapExpression;
            var typeMapSourceParameter      = mapExpression.Parameters[0];
            var typeMapDestinationParameter = mapExpression.Parameters[1];
            var requestedSourceType         = mapRequest.RequestedTypes.SourceType;
            var requestedDestinationType    = mapRequest.RequestedTypes.DestinationType;

            if (typeMapSourceParameter.Type != requestedSourceType || typeMapDestinationParameter.Type != requestedDestinationType)
            {
                var requestedSourceParameter      = Parameter(requestedSourceType, "source");
                var requestedDestinationParameter = Parameter(requestedDestinationType, "typeMapDestination");
                var contextParameter = Parameter(typeof(ResolutionContext), "context");

                mapExpression = Lambda(ToType(Invoke(typeMap.MapExpression,
                                                     ToType(requestedSourceParameter, typeMapSourceParameter.Type),
                                                     ToType(requestedDestinationParameter, typeMapDestinationParameter.Type),
                                                     contextParameter
                                                     ), mapRequest.RuntimeTypes.DestinationType),
                                       requestedSourceParameter, requestedDestinationParameter, contextParameter);
            }

            return(mapExpression);
        }
Exemplo n.º 34
0
 public override int GetHashCode() => TypeMap.GetHashCode();
Exemplo n.º 35
0
        private void ApplyInheritedTypeMap(TypeMap inheritedTypeMap)
        {
            foreach (var inheritedMappedProperty in inheritedTypeMap.GetPropertyMaps().Where(m => m.IsMapped()))
            {
                var conventionPropertyMap = GetPropertyMaps()
                    .SingleOrDefault(m =>
                        m.DestinationProperty.Name == inheritedMappedProperty.DestinationProperty.Name);

                if (conventionPropertyMap != null && inheritedMappedProperty.HasCustomValueResolver && !conventionPropertyMap.HasCustomValueResolver)
                {
                    conventionPropertyMap.AssignCustomValueResolver(
                        inheritedMappedProperty.GetSourceValueResolvers().First());
                    conventionPropertyMap.AssignCustomExpression(inheritedMappedProperty.CustomExpression);
                }
                else if (conventionPropertyMap == null)
                {
                    var propertyMap = new PropertyMap(inheritedMappedProperty);

                    AddInheritedPropertyMap(propertyMap);
                }
            }

            //Include BeforeMap
            if (inheritedTypeMap.BeforeMap != null)
                AddBeforeMapAction(inheritedTypeMap.BeforeMap);
            //Include AfterMap
            if (inheritedTypeMap.AfterMap != null)
                AddAfterMapAction(inheritedTypeMap.AfterMap);
        }
Exemplo n.º 36
0
            public SourceMappingExpression(TypeMap typeMap, LambdaExpression sourceMember)
            {
                var memberInfo = ReflectionHelper.FindProperty(sourceMember);

                _sourcePropertyConfig = typeMap.FindOrCreateSourceMemberConfigFor(memberInfo);
            }
 public TypeMapConfigErrors(TypeMap typeMap, string[] unmappedPropertyNames)
 {
     TypeMap = typeMap;
     UnmappedPropertyNames = unmappedPropertyNames;
 }
Exemplo n.º 38
0
        public IMappingExpression <TSource, TDestination> CreateMap <TSource, TDestination>(string profileName)
        {
            TypeMap typeMap = CreateTypeMap(typeof(TSource), typeof(TDestination), profileName);

            return(CreateMappingExpression <TSource, TDestination>(typeMap));
        }
Exemplo n.º 39
0
 private ValidationContext(TypePair types, PropertyMap propertyMap, IObjectMapper objectMapper, TypeMap typeMap)
 {
     ObjectMapper = objectMapper;
     TypeMap      = typeMap;
     Types        = types;
     PropertyMap  = propertyMap;
 }
Exemplo n.º 40
0
        private void Configure(TypeMapRegistry typeMapRegistry, TypeMap typeMap)
        {
            foreach (var action in AllTypeMapActions)
            {
                var expression = new MappingExpression(typeMap.Types, typeMap.ConfiguredMemberList);

                action(typeMap, expression);

                expression.Configure(typeMap);
            }

            foreach (var action in AllPropertyMapActions)
            {
                foreach (var propertyMap in typeMap.GetPropertyMaps())
                {
                    var memberExpression = new MappingExpression.MemberConfigurationExpression(propertyMap.DestinationProperty, typeMap.SourceType);

                    action(propertyMap, memberExpression);

                    memberExpression.Configure(typeMap);
                }
            }

            ApplyBaseMaps(typeMapRegistry, typeMap, typeMap);
            ApplyDerivedMaps(typeMapRegistry, typeMap, typeMap);
        }
Exemplo n.º 41
0
        private IMappingExpression <TSource, TDestination> CreateMappingExpression <TSource, TDestination>(TypeMap typeMap)
        {
            IMappingExpression <TSource, TDestination> mappingExp =
                new MappingExpression <TSource, TDestination>(typeMap, _serviceCtor, this);
            // Custom Hack
            var destInfo = new TypeInfo(typeof(TDestination));

            foreach (var destProperty in destInfo.GetPublicWriteAccessors())
            {
                object[] attrs = destProperty.GetCustomAttributes(true);
                if (attrs.Any(x => x is IgnoreMapAttribute))
                {
                    mappingExp = mappingExp.ForMember(destProperty.Name, y => y.Ignore());
                }
            }

            return(mappingExp);
        }
Exemplo n.º 42
0
 private void ApplyDerivedMaps(TypeMapRegistry typeMapRegistry, TypeMap baseMap, TypeMap typeMap)
 {
     foreach (var inheritedTypeMap in typeMap.IncludedDerivedTypes.Select(typeMapRegistry.GetTypeMap).Where(map => map != null))
     {
         inheritedTypeMap.ApplyInheritedMap(baseMap);
         ApplyDerivedMaps(typeMapRegistry, baseMap, inheritedTypeMap);
     }
 }
Exemplo n.º 43
0
 public PropertyMap(MemberInfo destinationMember, TypeMap typeMap)
 {
     TypeMap           = typeMap;
     DestinationMember = destinationMember;
 }
        public AutoMapperConfigurationException(TypeMap typeMap, string mismatchedPropertyName)
            : base(string.Format(
					"The following property on {0} cannot be mapped: \n\t{2}\nAdd a custom mapping expression, ignore, add a custom resolver, or modify the destination type {1}.",
					typeMap.DestinationType.FullName, typeMap.SourceType.FullName, mismatchedPropertyName))
        {
        }
Exemplo n.º 45
0
 public PropertyMap(PropertyMap inheritedMappedProperty, TypeMap typeMap)
     : this(inheritedMappedProperty.DestinationMember, typeMap) => ApplyInheritedPropertyMap(inheritedMappedProperty);
Exemplo n.º 46
0
 public void ApplyInheritedMap(TypeMap inheritedTypeMap)
 {
     _inheritedTypeMaps.Add(inheritedTypeMap);
 }
Exemplo n.º 47
0
 public PropertyMap(PropertyMap includedMemberMap, TypeMap typeMap, IncludedMember includedMember)
     : this(includedMemberMap, typeMap) => IncludedMember = includedMember.Chain(includedMemberMap.IncludedMember);
 public AutoMapperMappingException(string message, Exception innerException, TypePair types, TypeMap typeMap)
     : this(message, innerException, types)
 {
     TypeMap = typeMap;
 }
 public TypeMapConfigErrors(TypeMap typeMap, string[] unmappedPropertyNames, bool canConstruct)
 {
     TypeMap = typeMap;
     UnmappedPropertyNames = unmappedPropertyNames;
     CanConstruct = canConstruct;
 }
 public TypeMapCreatedEventArgs(TypeMap typeMap)
 {
     TypeMap = typeMap;
 }
Exemplo n.º 51
0
 public MapperFuncs(MapRequest mapRequest, TypeMap typeMap) : this(mapRequest, GenerateTypeMapExpression(mapRequest, typeMap))
 {
 }
 public AutoMapperMappingException(string message, Exception innerException, TypePair types, TypeMap typeMap, PropertyMap propertyMap)
     : this(message, innerException, types, typeMap)
 {
     PropertyMap = propertyMap;
 }
Exemplo n.º 53
0
 public void ApplyInheritedMap(TypeMap inheritedTypeMap)
 {
     _inheritedTypeMaps.Add(inheritedTypeMap);
 }
Exemplo n.º 54
0
 public bool Equals(TypeMap other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other._sourceType, _sourceType) && Equals(other._destinationType, _destinationType);
 }
Exemplo n.º 55
0
 public void AssertConfigurationIsValid(TypeMap typeMap)
 {
     AssertConfigurationIsValid(Enumerable.Repeat(typeMap, 1));
 }
Exemplo n.º 56
0
		public TypeMapCreatedEventArgs(TypeMap typeMap)
		{
			TypeMap = typeMap;
		}
Exemplo n.º 57
0
        private IMappingExpression <TSource, TDestination> CreateMappingExpression <TSource, TDestination>(TypeMap typeMap)
        {
            IMappingExpression <TSource, TDestination> mappingExp =
                new MappingExpression <TSource, TDestination>(typeMap, _serviceCtor, this);

            var type     = (typeMap.ConfiguredMemberList == MemberList.Destination) ? typeof(TDestination) : typeof(TSource);
            var destInfo = new TypeInfo(type, ShouldMapProperty, ShouldMapField);

            foreach (var destProperty in destInfo.PublicWriteAccessors)
            {
                var attrs = destProperty.GetCustomAttributes(true);
                if (attrs.Any(x => x is IgnoreMapAttribute))
                {
                    mappingExp = mappingExp.ForMember(destProperty.Name, y => y.Ignore());
                }
                if (_globalIgnore.Contains(destProperty.Name))
                {
                    mappingExp = mappingExp.ForMember(destProperty.Name, y => y.Ignore());
                }
            }

            return(mappingExp);
        }
Exemplo n.º 58
0
 private static bool ShouldCheckMap(TypeMap typeMap)
 {
     return((typeMap.CustomMapper == null && typeMap.CustomProjection == null &&
             typeMap.DestinationTypeOverride == null) && !FeatureDetector.IsIDataRecordType(typeMap.SourceType));
 }
Exemplo n.º 59
0
 public TypeMapWrapper(TypeMap typeMap)
 {
     DestinationType = typeMap.DestinationType;
 }