public ConfigurationValidator( IGlobalConfiguration config, IGlobalConfigurationExpression expression ) { _validators = expression.GetValidators(); _config = config; _expression = expression; }
public ProfileMap(IProfileConfiguration profile, IGlobalConfigurationExpression configuration = null) { var globalProfile = (IProfileConfiguration)configuration; Name = profile.ProfileName; AllowNullCollections = profile.AllowNullCollections ?? configuration?.AllowNullCollections ?? false; AllowNullDestinationValues = profile.AllowNullDestinationValues ?? configuration?.AllowNullDestinationValues ?? true; EnableNullPropagationForQueryMapping = profile.EnableNullPropagationForQueryMapping ?? configuration?.EnableNullPropagationForQueryMapping ?? false; ConstructorMappingEnabled = profile.ConstructorMappingEnabled ?? globalProfile?.ConstructorMappingEnabled ?? true; MethodMappingEnabled = profile.MethodMappingEnabled ?? globalProfile?.MethodMappingEnabled ?? true; FieldMappingEnabled = profile.FieldMappingEnabled ?? globalProfile?.FieldMappingEnabled ?? true; ShouldMapField = profile.ShouldMapField ?? configuration?.ShouldMapField ?? (p => p.IsPublic); ShouldMapProperty = profile.ShouldMapProperty ?? configuration?.ShouldMapProperty ?? (p => p.IsPublic()); ShouldMapMethod = profile.ShouldMapMethod ?? configuration?.ShouldMapMethod ?? (p => !p.IsSpecialName); ShouldUseConstructor = profile.ShouldUseConstructor ?? configuration?.ShouldUseConstructor ?? (c => true); ValueTransformers = profile.ValueTransformers.Concat(configuration?.ValueTransformers).ToArray(); _memberConfigurations = profile.MemberConfigurations.Concat(globalProfile?.MemberConfigurations).ToArray(); var nameSplitMember = _memberConfigurations[0].MemberMappers.OfType <NameSplitMember>().FirstOrDefault(); if (nameSplitMember != null) { nameSplitMember.SourceMemberNamingConvention = profile.SourceMemberNamingConvention ?? PascalCaseNamingConvention.Instance; nameSplitMember.DestinationMemberNamingConvention = profile.DestinationMemberNamingConvention ?? PascalCaseNamingConvention.Instance; } GlobalIgnores = profile.GlobalIgnores.Concat(globalProfile?.GlobalIgnores).ToArray(); SourceExtensionMethods = profile.SourceExtensionMethods.Concat(globalProfile?.SourceExtensionMethods).ToArray(); AllPropertyMapActions = profile.AllPropertyMapActions.Concat(globalProfile?.AllPropertyMapActions).ToArray(); AllTypeMapActions = profile.AllTypeMapActions.Concat(globalProfile?.AllTypeMapActions).ToArray(); var prePostFixes = profile.MemberConfigurations.Concat(globalProfile?.MemberConfigurations) .Select(m => m.NameMapper) .SelectMany(m => m.NamedMappers) .OfType <PrePostfixName>() .ToArray(); Prefixes = prePostFixes.SelectMany(m => m.Prefixes).Distinct().ToList(); Postfixes = prePostFixes.SelectMany(m => m.Postfixes).Distinct().ToList(); SetTypeMapConfigs(); SetOpenTypeMapConfigs(); _typeDetails = new(2 * _typeMapConfigs.Length); return; void SetTypeMapConfigs() { _typeMapConfigs = new ITypeMapConfiguration[profile.TypeMapConfigs.Count]; var index = 0; var reverseMapsCount = 0; foreach (var typeMapConfig in profile.TypeMapConfigs) { _typeMapConfigs[index++] = typeMapConfig; if (typeMapConfig.ReverseTypeMap != null) { reverseMapsCount++; } } TypeMapsCount = index + reverseMapsCount; } void SetOpenTypeMapConfigs() { _openTypeMapConfigs = new(profile.OpenTypeMapConfigs.Count); foreach (var openTypeMapConfig in profile.OpenTypeMapConfigs) { _openTypeMapConfigs.Add(openTypeMapConfig.Types, openTypeMapConfig); var reverseMap = openTypeMapConfig.ReverseTypeMap; if (reverseMap != null) { _openTypeMapConfigs.Add(reverseMap.Types, reverseMap); } } } }