Esempio 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;
        }
Esempio 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;
        }
Esempio 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;
        }
Esempio 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;
        }
Esempio 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;
        }
Esempio 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;
        }
Esempio 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))
        {
        }
 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
         };
     }
 }
Esempio 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;
        }
Esempio n. 12
0
 public MappingExpression(TypeMap typeMap, Func <Type, object> typeConverterCtor)
 {
     _typeMap           = typeMap;
     _typeConverterCtor = typeConverterCtor;
 }
Esempio 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);
            }
        }
Esempio 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));
        }
Esempio 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);
        }
Esempio 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)
 {
 }
Esempio n. 17
0
 private void ApplyMemberMaps(TypeMap mainMap, IConfigurationProvider configurationProvider)
 {
     AddMemberMaps(mainMap.IncludedMembers, mainMap, configurationProvider);
     AddMemberMaps(mainMap.GetUntypedIncludedMembers(), mainMap, configurationProvider);
 }
Esempio n. 18
0
 protected void OnTypeMapCreated(TypeMap typeMap)
 {
     TypeMapCreated?.Invoke(this, new TypeMapCreatedEventArgs(typeMap));
 }
Esempio 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;
 }
Esempio n. 21
0
 internal void ValidateMap(TypeMap typeMap)
 => ConfigurationProvider.AssertConfigurationIsValid(typeMap);
Esempio n. 22
0
 internal void IncrementTypeDepth(TypeMap typeMap) => TypeDepth[typeMap.Types]++;
Esempio n. 23
0
 public PropertyMap(PropertyMap includedMemberMap, TypeMap typeMap, LambdaExpression expression)
     : this(includedMemberMap, typeMap) => ApplyIncludedMemberMap(includedMemberMap, expression);
Esempio n. 24
0
 public void RegisterTypeMap(TypeMap typeMap) => _typeMaps[typeMap.Types] = typeMap;
Esempio n. 25
0
        private IMappingExpression CreateMappingExpression(TypeMap typeMap, Type destinationType)
        {
            var mappingExp = new MappingExpression(typeMap, _serviceCtor, this);

            return((IMappingExpression)Ignore(mappingExp, destinationType));
        }
Esempio n. 26
0
 public void InheritTypes(TypeMap inheritedTypeMap)
 {
     foreach (var includedDerivedType in inheritedTypeMap._includedDerivedTypes
         .Where(includedDerivedType => !_includedDerivedTypes.Contains(includedDerivedType)))
     {
         _includedDerivedTypes.Add(includedDerivedType);
     }
 }
Esempio 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);
            }
        }
Esempio n. 28
0
 public ConstructorMap(ConstructorInfo ctor, TypeMap typeMap)
 {
     Ctor = ctor;
     TypeMap = typeMap;
 }
Esempio 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);
     }
 }
Esempio 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);
            }
        }
Esempio n. 31
0
 public ValidationContext(TypePair types, PropertyMap propertyMap, TypeMap typeMap) : this(types, propertyMap, null, typeMap)
 {
 }
Esempio n. 32
0
 public PathMap(LambdaExpression destinationExpression, MemberPath memberPath, TypeMap typeMap)
 {
     MemberPath            = memberPath;
     TypeMap               = typeMap;
     DestinationExpression = destinationExpression;
 }
Esempio 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);
        }
Esempio n. 34
0
 public override int GetHashCode() => TypeMap.GetHashCode();
Esempio 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);
        }
Esempio 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;
 }
Esempio 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));
        }
Esempio n. 39
0
 private ValidationContext(TypePair types, PropertyMap propertyMap, IObjectMapper objectMapper, TypeMap typeMap)
 {
     ObjectMapper = objectMapper;
     TypeMap      = typeMap;
     Types        = types;
     PropertyMap  = propertyMap;
 }
Esempio 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);
        }
Esempio 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);
        }
Esempio 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);
     }
 }
Esempio 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))
        {
        }
Esempio n. 45
0
 public PropertyMap(PropertyMap inheritedMappedProperty, TypeMap typeMap)
     : this(inheritedMappedProperty.DestinationMember, typeMap) => ApplyInheritedPropertyMap(inheritedMappedProperty);
Esempio n. 46
0
 public void ApplyInheritedMap(TypeMap inheritedTypeMap)
 {
     _inheritedTypeMaps.Add(inheritedTypeMap);
 }
Esempio 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;
 }
Esempio 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;
 }
Esempio n. 53
0
 public void ApplyInheritedMap(TypeMap inheritedTypeMap)
 {
     _inheritedTypeMaps.Add(inheritedTypeMap);
 }
Esempio 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);
 }
Esempio n. 55
0
 public void AssertConfigurationIsValid(TypeMap typeMap)
 {
     AssertConfigurationIsValid(Enumerable.Repeat(typeMap, 1));
 }
Esempio n. 56
0
		public TypeMapCreatedEventArgs(TypeMap typeMap)
		{
			TypeMap = typeMap;
		}
Esempio 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);
        }
Esempio n. 58
0
 private static bool ShouldCheckMap(TypeMap typeMap)
 {
     return((typeMap.CustomMapper == null && typeMap.CustomProjection == null &&
             typeMap.DestinationTypeOverride == null) && !FeatureDetector.IsIDataRecordType(typeMap.SourceType));
 }
Esempio n. 59
0
 public TypeMapWrapper(TypeMap typeMap)
 {
     DestinationType = typeMap.DestinationType;
 }