public void Configure(TypeMap typeMap)
        {
            foreach (var destProperty in typeMap.DestinationTypeDetails.PublicWriteAccessors)
            {
                if (destProperty.Has <IgnoreMapAttribute>())
                {
                    IgnoreDestinationMember(destProperty);
                    var sourceProperty = typeMap.SourceType.GetInheritedMember(destProperty.Name);
                    if (sourceProperty != null)
                    {
                        ReverseMapExpression?.IgnoreDestinationMember(sourceProperty);
                    }
                }
                if (typeMap.Profile.GlobalIgnores.Contains(destProperty.Name) && GetDestinationMemberConfiguration(destProperty) == null)
                {
                    IgnoreDestinationMember(destProperty);
                }
            }
            MapDestinationCtorToSource(typeMap, CtorParamConfigurations);
            foreach (var action in TypeMapActions)
            {
                action(typeMap);
            }
            foreach (var memberConfig in MemberConfigurations)
            {
                memberConfig.Configure(typeMap);
            }
            foreach (var memberConfig in SourceMemberConfigurations)
            {
                memberConfig.Configure(typeMap);
            }
            foreach (var paramConfig in CtorParamConfigurations)
            {
                paramConfig.Configure(typeMap);
            }
            foreach (var valueTransformer in ValueTransformers)
            {
                typeMap.AddValueTransformation(valueTransformer);
            }

            Features.Configure(typeMap);

            if (ReverseMapExpression != null)
            {
                ReverseSourceMembers(typeMap);
                foreach (var destProperty in typeMap.PropertyMaps.Where(pm => pm.Ignored))
                {
                    ReverseMapExpression.ForSourceMemberCore(destProperty.DestinationName, opt => opt.DoNotValidate());
                }
                foreach (var includedDerivedType in typeMap.IncludedDerivedTypes)
                {
                    ReverseMapExpression.IncludeCore(includedDerivedType.DestinationType, includedDerivedType.SourceType);
                }
                foreach (var includedBaseType in typeMap.IncludedBaseTypes)
                {
                    ReverseMapExpression.IncludeBaseCore(includedBaseType.DestinationType, includedBaseType.SourceType);
                }
                ReverseIncludedMembers(typeMap);
            }
        }
Exemple #2
0
 private void ConfigureReverseMap(TypeMap typeMap)
 {
     ReverseSourceMembers(typeMap);
     foreach (var destProperty in typeMap.PropertyMaps.Where(pm => pm.Ignored))
     {
         ReverseMapExpression.ForSourceMemberCore(destProperty.DestinationName, opt => opt.DoNotValidate());
     }
     foreach (var includedDerivedType in typeMap.IncludedDerivedTypes)
     {
         ReverseMapExpression.IncludeCore(includedDerivedType.DestinationType, includedDerivedType.SourceType);
     }
     foreach (var includedBaseType in typeMap.IncludedBaseTypes)
     {
         ReverseMapExpression.IncludeBaseCore(includedBaseType.DestinationType, includedBaseType.SourceType);
     }
     ReverseIncludedMembers(typeMap);
 }
        public void Configure(TypeMap typeMap)
        {
            foreach (var destProperty in typeMap.DestinationTypeDetails.PublicWriteAccessors)
            {
                var attrs = destProperty.GetCustomAttributes(true);
                if (attrs.Any(x => x is IgnoreMapAttribute))
                {
                    IgnoreDestinationMember(destProperty);
                    var sourceProperty = typeMap.SourceType.GetInheritedMember(destProperty.Name);
                    if (sourceProperty != null)
                    {
                        ReverseMapExpression?.IgnoreDestinationMember(sourceProperty);
                    }
                }
                if (typeMap.Profile.GlobalIgnores.Contains(destProperty.Name) && GetDestinationMemberConfiguration(destProperty) == null)
                {
                    IgnoreDestinationMember(destProperty);
                }
            }

            var destTypeInfo = typeMap.DestinationTypeDetails;

            if (!typeMap.DestinationType.IsAbstract)
            {
                foreach (var destCtor in destTypeInfo.Constructors.OrderByDescending(ci => ci.GetParameters().Length))
                {
                    if (typeMap.Profile.MapDestinationCtorToSource(typeMap, destCtor, typeMap.SourceTypeDetails, CtorParamConfigurations))
                    {
                        break;
                    }
                }
            }


            foreach (var action in TypeMapActions)
            {
                action(typeMap);
            }
            foreach (var memberConfig in MemberConfigurations)
            {
                memberConfig.Configure(typeMap);
            }
            foreach (var memberConfig in SourceMemberConfigurations)
            {
                memberConfig.Configure(typeMap);
            }
            foreach (var paramConfig in CtorParamConfigurations)
            {
                paramConfig.Configure(typeMap);
            }
            foreach (var valueTransformer in ValueTransformers)
            {
                typeMap.AddValueTransformation(valueTransformer);
            }

            Features.Configure(typeMap);

            if (ReverseMapExpression != null)
            {
                ReverseSourceMembers(typeMap);
                foreach (var destProperty in typeMap.PropertyMaps.Where(pm => pm.Ignored))
                {
                    ReverseMapExpression.ForSourceMemberCore(destProperty.DestinationName, opt => opt.DoNotValidate());
                }
                foreach (var includedDerivedType in typeMap.IncludedDerivedTypes)
                {
                    ReverseMapExpression.IncludeCore(includedDerivedType.DestinationType, includedDerivedType.SourceType);
                }
                foreach (var includedBaseType in typeMap.IncludedBaseTypes)
                {
                    ReverseMapExpression.IncludeBaseCore(includedBaseType.DestinationType, includedBaseType.SourceType);
                }
                ReverseIncludedMembers(typeMap);
            }
        }