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(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(IConfiguration configuration) { ServiceCtor = configuration.ServiceCtor; AllowNullDestinationValues = configuration.AllowNullDestinationValues; AllowNullCollections = configuration.AllowNullCollections; 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.TypePair, 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.DestMember, 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.TypePair] = typeMap; if (typeMap.DestinationTypeOverride != null) { redirectedTypes.Add(Tuple.Create(typeMap.TypePair, 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.TypePair)); } 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); } }
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(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); }