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();

            foreach (var beforeSealAction in configurationExpression.Advanced.BeforeSealActions)
            {
                beforeSealAction?.Invoke(this);
            }
            Seal();
        }
        public MapperConfiguration(MapperConfigurationExpression configurationExpression)
        {
            _mappers          = configurationExpression.Mappers.ToArray();
            _resolvedMaps     = new LockingConcurrentDictionary <TypePair, TypeMap>(GetTypeMap);
            _executionPlans   = new LockingConcurrentDictionary <MapRequest, Delegate>(CompileExecutionPlan);
            _validator        = new ConfigurationValidator(this, 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();
            RecursiveQueriesMaxDepth = configurationExpression.Advanced.RecursiveQueriesMaxDepth;

            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();
        }
Esempio n. 3
0
 protected Profile()
 {
     _typeDetails = new LockingConcurrentDictionary <Type, TypeDetails>(CreateTypeDetails);
     ProfileName  = GetType().FullName;
     IncludeSourceExtensionMethods(typeof(Enumerable));
     _memberConfigurations.Add(new MemberConfiguration().AddMember <NameSplitMember>().AddName <PrePostfixName>(_ => _.AddStrings(p => p.Prefixes, "Get")));
 }
Esempio n. 4
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();
        }
        public MapperConfiguration(MapperConfigurationExpression configurationExpression, IEnumerable <IObjectMapper> mappers)
        {
            _mappers          = mappers;
            _mapPlanCache     = new LockingConcurrentDictionary <MapRequest, MapperFuncs>(CreateMapperFuncs);
            _validator        = new ConfigurationValidator(this);
            ExpressionBuilder = new ExpressionBuilder(this);

            Configuration = configurationExpression;

            Seal(Configuration);
        }
Esempio n. 6
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();

            var nameSplitMember = _memberConfigurations[0].MemberMappers.OfType <NameSplitMember>().FirstOrDefault();

            if (nameSplitMember != null)
            {
                nameSplitMember.SourceMemberNamingConvention      = profile.SourceMemberNamingConvention;
                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)
                .ToList();

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

            _typeMapConfigs     = profile.TypeMapConfigs.ToArray();
            _openTypeMapConfigs = profile.OpenTypeMapConfigs.ToArray();
        }
Esempio n. 7
0
        public MapperConfiguration(MapperConfigurationExpression configurationExpression, IEnumerable <IObjectMapper> mappers)
        {
            _mappers          = mappers;
            _mapPlanCache     = new LockingConcurrentDictionary <MapRequest, MapperFuncs>(CreateMapperFuncs);
            _validator        = new ConfigurationValidator(this);
            ExpressionBuilder = new ExpressionBuilder(this);

            ServiceCtor = configurationExpression.ServiceCtor;
            EnableNullPropagationForQueryMapping = configurationExpression.EnableNullPropagationForQueryMapping ?? false;

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

            Seal();
        }