private void Configure(TypeMap typeMap, IConfigurationProvider configurationProvider) { foreach (var action in AllTypeMapActions) { var expression = new MappingExpression(typeMap.Types, typeMap.ConfiguredMemberList); action(typeMap, expression); expression.Configure(typeMap); } foreach (var action in AllPropertyMapActions) { foreach (var propertyMap in typeMap.PropertyMaps) { var memberExpression = new MappingExpression.MemberConfigurationExpression(propertyMap.DestinationMember, typeMap.SourceType); action(propertyMap, memberExpression); memberExpression.Configure(typeMap); } } ApplyBaseMaps(typeMap, typeMap, configurationProvider); ApplyDerivedMaps(typeMap, typeMap, configurationProvider); ApplyMemberMaps(typeMap, configurationProvider); }
private void Configure(TypeMapRegistry typeMapRegistry, TypeMap typeMap) { foreach (var action in _allTypeMapActions) { var expression = new MappingExpression(typeMap.Types, typeMap.ConfiguredMemberList); action(typeMap, expression); expression.Configure(this, typeMap); } foreach (var action in _allPropertyMapActions) { foreach (var propertyMap in typeMap.GetPropertyMaps()) { var memberExpression = new MappingExpression.MemberConfigurationExpression(propertyMap.DestinationProperty, typeMap.SourceType); action(propertyMap, memberExpression); memberExpression.Configure(typeMap); } } ApplyBaseMaps(typeMapRegistry, typeMap, typeMap); ApplyDerivedMaps(typeMapRegistry, typeMap, typeMap); }
private void Seal() { var derivedMaps = new List <Tuple <TypePair, TypeMap> >(); var redirectedTypes = new List <Tuple <TypePair, TypePair> >(); foreach (var profile in _profiles.Cast <IProfileConfiguration>()) { profile.Register(_typeMapRegistry); } foreach (var action in _allTypeMapActions) { foreach (var typeMap in _typeMapRegistry.TypeMaps) { var expression = new MappingExpression(typeMap.Types, typeMap.ConfiguredMemberList); action(typeMap, expression); expression.Configure(typeMap.Profile, typeMap); } } foreach (var profile in _profiles.Cast <IProfileConfiguration>()) { profile.Configure(_typeMapRegistry); } foreach (var typeMap in _typeMapRegistry.TypeMaps) { _typeMapPlanCache[typeMap.Types] = typeMap; if (typeMap.DestinationTypeOverride != null) { redirectedTypes.Add(Tuple.Create(typeMap.Types, new TypePair(typeMap.SourceType, typeMap.DestinationTypeOverride))); } if (typeMap.SourceType.IsNullableType()) { var nonNullableTypes = new TypePair(Nullable.GetUnderlyingType(typeMap.SourceType), typeMap.DestinationType); redirectedTypes.Add(Tuple.Create(nonNullableTypes, typeMap.Types)); } derivedMaps.AddRange(GetDerivedTypeMaps(typeMap).Select(derivedMap => Tuple.Create(new TypePair(derivedMap.SourceType, typeMap.DestinationType), derivedMap))); } foreach (var redirectedType in redirectedTypes) { var derivedMap = FindTypeMapFor(redirectedType.Item2); if (derivedMap != null) { _typeMapPlanCache[redirectedType.Item1] = derivedMap; } } foreach (var derivedMap in derivedMaps.Where(derivedMap => !_typeMapPlanCache.ContainsKey(derivedMap.Item1))) { _typeMapPlanCache[derivedMap.Item1] = derivedMap.Item2; } foreach (var typeMap in _typeMapRegistry.TypeMaps) { typeMap.Seal(_typeMapRegistry, this); } }
public TypeMap CreateConventionTypeMap(TypeMapRegistry typeMapRegistry, TypePair types) { var typeMap = _typeMapFactory.CreateTypeMap(types.SourceType, types.DestinationType, this, MemberList.Destination); var config = new MappingExpression(typeMap.Types, typeMap.ConfiguredMemberList); config.Configure(typeMap); Configure(typeMapRegistry, typeMap); return(typeMap); }
private void Configure(TypeMapRegistry typeMapRegistry, TypeMap typeMap) { foreach (var action in _allTypeMapActions) { var expression = new MappingExpression(typeMap.Types, typeMap.ConfiguredMemberList); action(typeMap, expression); expression.Configure(this, typeMap); } ApplyBaseMaps(typeMapRegistry, typeMap, typeMap); ApplyDerivedMaps(typeMapRegistry, typeMap, typeMap); }
public TypeMap CreateConventionTypeMap(TypePair types, IConfigurationProvider configurationProvider) { var typeMap = _typeMapFactory.CreateTypeMap(types.SourceType, types.DestinationType, this); typeMap.IsConventionMap = true; var config = new MappingExpression(typeMap.Types, typeMap.ConfiguredMemberList); config.Configure(typeMap); Configure(typeMap, configurationProvider); return(typeMap); }
TypeMap IProfileConfiguration.ConfigureConventionTypeMap(TypeMapRegistry typeMapRegistry, TypePair types) { if (!TypeConfigurations.Any(c => c.IsMatch(types))) { return(null); } var typeMap = _typeMapFactory.CreateTypeMap(types.SourceType, types.DestinationType, this, MemberList.Destination); var config = new MappingExpression(typeMap.Types, typeMap.ConfiguredMemberList); config.Configure(this, typeMap); Configure(typeMapRegistry, typeMap); return(typeMap); }
private void Seal(IConfiguration configuration) { ServiceCtor = configuration.ServiceCtor; AllowNullDestinationValues = configuration.AllowNullDestinationValues; AllowNullCollections = configuration.AllowNullCollections; EnableNullPropagationForQueryMapping = configuration.EnableNullPropagationForQueryMapping; var derivedMaps = new List <Tuple <TypePair, TypeMap> >(); var redirectedTypes = new List <Tuple <TypePair, TypePair> >(); foreach (var profile in configuration.Profiles.Cast <IProfileConfiguration>()) { profile.Register(_typeMapRegistry); } foreach (var action in configuration.AllTypeMapActions) { foreach (var typeMap in _typeMapRegistry.TypeMaps) { var expression = new MappingExpression(typeMap.Types, typeMap.ConfiguredMemberList); action(typeMap, expression); expression.Configure(typeMap.Profile, typeMap); } } foreach (var action in configuration.AllPropertyMapActions) { foreach (var typeMap in _typeMapRegistry.TypeMaps) { foreach (var propertyMap in typeMap.GetPropertyMaps()) { var memberExpression = new MappingExpression.MemberConfigurationExpression(propertyMap.DestinationProperty, typeMap.SourceType); action(propertyMap, memberExpression); memberExpression.Configure(typeMap); } } } foreach (var profile in configuration.Profiles.Cast <IProfileConfiguration>()) { profile.Configure(_typeMapRegistry); } foreach (var typeMap in _typeMapRegistry.TypeMaps) { _typeMapPlanCache[typeMap.Types] = typeMap; if (typeMap.DestinationTypeOverride != null) { redirectedTypes.Add(Tuple.Create(typeMap.Types, new TypePair(typeMap.SourceType, typeMap.DestinationTypeOverride))); } derivedMaps.AddRange(GetDerivedTypeMaps(typeMap).Select(derivedMap => Tuple.Create(new TypePair(derivedMap.SourceType, typeMap.DestinationType), derivedMap))); } foreach (var redirectedType in redirectedTypes) { var derivedMap = FindTypeMapFor(redirectedType.Item2); if (derivedMap != null) { _typeMapPlanCache[redirectedType.Item1] = derivedMap; } } foreach (var derivedMap in derivedMaps.Where(derivedMap => !_typeMapPlanCache.ContainsKey(derivedMap.Item1))) { _typeMapPlanCache[derivedMap.Item1] = derivedMap.Item2; } foreach (var typeMap in _typeMapRegistry.TypeMaps) { typeMap.Seal(_typeMapRegistry, this); } }