Example #1
0
        public ProfileMap(IProfileConfiguration profile, IConfiguration configuration)
        {
            _typeDetails = new LockingConcurrentDictionary <Type, TypeDetails>(TypeDetailsFactory);

            _extraMembersByType          = profile.ExtraMembersByType;
            _extraMemberGetterStrategies = profile.ExtraMemberGetterStrategies;
            _extraMemberSetterStrategies = profile.ExtraMemberSetterStrategies;


            Name = profile.ProfileName;
            AllowNullCollections                 = profile.AllowNullCollections ?? configuration?.AllowNullCollections ?? false;
            AllowNullDestinationValues           = profile.AllowNullDestinationValues ?? configuration?.AllowNullDestinationValues ?? true;
            EnableNullPropagationForQueryMapping = profile.EnableNullPropagationForQueryMapping ?? configuration?.EnableNullPropagationForQueryMapping ?? false;
            ConstructorMappingEnabled            = profile.ConstructorMappingEnabled ?? configuration?.ConstructorMappingEnabled ?? true;
            ShouldMapField        = profile.ShouldMapField ?? configuration?.ShouldMapField ?? (p => p.IsPublic());
            ShouldMapProperty     = profile.ShouldMapProperty ?? configuration?.ShouldMapProperty ?? (p => p.IsPublic());
            CreateMissingTypeMaps = profile.CreateMissingTypeMaps ?? configuration?.CreateMissingTypeMaps ?? false;

            TypeConfigurations = profile.TypeConfigurations
                                 .Concat(configuration?.TypeConfigurations ?? Enumerable.Empty <IConditionalObjectMapper>())
                                 .Concat(CreateMissingTypeMaps
                    ? Enumerable.Repeat(new ConditionalObjectMapper {
                Conventions = { tp => !ExcludedTypes.Contains(tp.SourceType) && !ExcludedTypes.Contains(tp.DestinationType) }
            }, 1)
                    : Enumerable.Empty <IConditionalObjectMapper>())
                                 .ToArray();

            ValueTransformers = profile.ValueTransformers.Concat(configuration?.ValueTransformers ?? Enumerable.Empty <ValueTransformerConfiguration>()).ToArray();

            MemberConfigurations = profile.MemberConfigurations.ToArray();

            MemberConfigurations.FirstOrDefault()?.AddMember <NameSplitMember>(_ => _.SourceMemberNamingConvention      = profile.SourceMemberNamingConvention);
            MemberConfigurations.FirstOrDefault()?.AddMember <NameSplitMember>(_ => _.DestinationMemberNamingConvention = profile.DestinationMemberNamingConvention);

            GlobalIgnores          = profile.GlobalIgnores.Concat(configuration?.GlobalIgnores ?? Enumerable.Empty <string>()).ToArray();
            SourceExtensionMethods = profile.SourceExtensionMethods.Concat(configuration?.SourceExtensionMethods ?? Enumerable.Empty <MethodInfo>()).ToArray();
            AllPropertyMapActions  = profile.AllPropertyMapActions.Concat(configuration?.AllPropertyMapActions ?? Enumerable.Empty <Action <PropertyMap, IMemberConfigurationExpression> >()).ToArray();
            AllTypeMapActions      = profile.AllTypeMapActions.Concat(configuration?.AllTypeMapActions ?? Enumerable.Empty <Action <TypeMap, IMappingExpression> >()).ToArray();

            Prefixes =
                profile.MemberConfigurations
                .Select(m => m.NameMapper)
                .SelectMany(m => m.NamedMappers)
                .OfType <PrePostfixName>()
                .SelectMany(m => m.Prefixes)
                .ToArray();

            Postfixes =
                profile.MemberConfigurations
                .Select(m => m.NameMapper)
                .SelectMany(m => m.NamedMappers)
                .OfType <PrePostfixName>()
                .SelectMany(m => m.Postfixes)
                .ToArray();

            _typeMapConfigs     = profile.TypeMapConfigs.ToArray();
            _openTypeMapConfigs = profile.OpenTypeMapConfigs.ToArray();
        }
Example #2
0
        public ProfileMap(IProfileConfiguration profile, IConfiguration configuration)
        {
            _typeDetails = new LockingConcurrentDictionary <Type, TypeDetails>(TypeDetailsFactory);

            Name = profile.ProfileName;
            AllowNullCollections                 = profile.AllowNullCollections ?? configuration?.AllowNullCollections ?? false;
            AllowNullDestinationValues           = profile.AllowNullDestinationValues ?? configuration?.AllowNullDestinationValues ?? true;
            EnableNullPropagationForQueryMapping = profile.EnableNullPropagationForQueryMapping ?? configuration?.EnableNullPropagationForQueryMapping ?? false;
            ConstructorMappingEnabled            = profile.ConstructorMappingEnabled ?? configuration?.ConstructorMappingEnabled ?? true;
            ShouldMapField       = profile.ShouldMapField ?? configuration?.ShouldMapField ?? (p => p.IsPublic());
            ShouldMapProperty    = profile.ShouldMapProperty ?? configuration?.ShouldMapProperty ?? (p => p.IsPublic());
            ShouldMapMethod      = profile.ShouldMapMethod ?? configuration?.ShouldMapMethod ?? (p => true);
            ShouldUseConstructor = profile.ShouldUseConstructor ?? configuration?.ShouldUseConstructor ?? (c => true);

            ValueTransformers = profile.ValueTransformers.Concat(configuration?.ValueTransformers ?? Enumerable.Empty <ValueTransformerConfiguration>()).ToArray();

            MemberConfigurations = profile.MemberConfigurations.Concat(configuration?.MemberConfigurations ?? Enumerable.Empty <IMemberConfiguration>()).ToArray();

            MemberConfigurations.FirstOrDefault()?.AddMember <NameSplitMember>(_ => _.SourceMemberNamingConvention      = profile.SourceMemberNamingConvention);
            MemberConfigurations.FirstOrDefault()?.AddMember <NameSplitMember>(_ => _.DestinationMemberNamingConvention = profile.DestinationMemberNamingConvention);

            GlobalIgnores          = profile.GlobalIgnores.Concat(configuration?.GlobalIgnores ?? Enumerable.Empty <string>()).ToArray();
            SourceExtensionMethods = profile.SourceExtensionMethods.Concat(configuration?.SourceExtensionMethods ?? Enumerable.Empty <MethodInfo>()).ToArray();
            AllPropertyMapActions  = profile.AllPropertyMapActions.Concat(configuration?.AllPropertyMapActions ?? Enumerable.Empty <Action <PropertyMap, IMemberConfigurationExpression> >()).ToArray();
            AllTypeMapActions      = profile.AllTypeMapActions.Concat(configuration?.AllTypeMapActions ?? Enumerable.Empty <Action <TypeMap, IMappingExpression> >()).ToArray();

            Prefixes =
                profile.MemberConfigurations
                .Select(m => m.NameMapper)
                .SelectMany(m => m.NamedMappers)
                .OfType <PrePostfixName>()
                .SelectMany(m => m.Prefixes)
                .ToArray();

            Postfixes =
                profile.MemberConfigurations
                .Select(m => m.NameMapper)
                .SelectMany(m => m.NamedMappers)
                .OfType <PrePostfixName>()
                .SelectMany(m => m.Postfixes)
                .ToArray();

            _typeMapConfigs     = profile.TypeMapConfigs.ToArray();
            _openTypeMapConfigs = profile.OpenTypeMapConfigs.ToArray();
        }
 protected IPropertyMapConfiguration GetDestinationMemberConfiguration(MemberInfo destinationMember) =>
 MemberConfigurations.FirstOrDefault(m => m.DestinationMember.Name == destinationMember.Name);