Exemplo n.º 1
0
        public MapperConfiguration(MapperConfigurationExpression configurationExpression)
        {
            _mappers             = configurationExpression.Mappers.ToArray();
            _typeMapPlanCache    = new LockingConcurrentDictionary <TypePair, TypeMap>(GetTypeMap);
            _mapPlanCache        = new LockingConcurrentDictionary <MapRequest, MapperFuncs>(CreateMapperFuncs);
            Validators           = configurationExpression.Advanced.GetValidators();
            _validator           = new ConfigurationValidator(this);
            _expressionValidator = new MapperConfigurationExpressionValidator(configurationExpression);
            ExpressionBuilder    = new ExpressionBuilder(this);

            ServiceCtor = configurationExpression.ServiceCtor;
            EnableNullPropagationForQueryMapping = configurationExpression.EnableNullPropagationForQueryMapping ?? false;
            MaxExecutionPlanDepth = configurationExpression.Advanced.MaxExecutionPlanDepth + 1;
            ResultConverters      = configurationExpression.Advanced.QueryableResultConverters.ToArray();
            Binders = configurationExpression.Advanced.QueryableBinders.ToArray();

            Configuration = new ProfileMap(configurationExpression);
            Profiles      = new[] { Configuration }.Concat(configurationExpression.Profiles.Select(p => new ProfileMap(p, configurationExpression))).ToArray();

            configurationExpression.Features.Configure(this);

            foreach (var beforeSealAction in configurationExpression.Advanced.BeforeSealActions)
            {
                beforeSealAction?.Invoke(this);
            }
            Seal();
        }
Exemplo n.º 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);
            CreateMissingTypeMaps = profile.CreateMissingTypeMaps ?? configuration?.CreateMissingTypeMaps ?? true;
            ValidateInlineMaps    = profile.ValidateInlineMaps ?? configuration?.ValidateInlineMaps ?? true;

            TypeConfigurations = profile.TypeConfigurations
                                 .Concat(configuration?.TypeConfigurations ?? 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();
        }