public GetPropertyMaps ( ) : PropertyMap[] | ||
Результат | PropertyMap[] |
public static IEnumerable<MapVisual> X(TypeMap map) { foreach (var propertyMap in map.GetPropertyMaps()) { yield return new MapVisual { SourceSystem = extractSystem(propertyMap.SourceMember), SourceValue = getValue(propertyMap.SourceMember), TargetSystem = extractSystem(propertyMap.DestinationProperty), TargetValue = propertyMap.DestinationProperty.Name }; } }
private void IncludeBaseMappings(Type source, Type destination, TypeMap typeMap) { foreach (var inheritedTypeMap in _typeMaps.Where(t => t.TypeHasBeenIncluded(source, destination))) { foreach (var inheritedMappedProperty in inheritedTypeMap.GetPropertyMaps().Where(m => m.IsMapped())) { var conventionPropertyMap = typeMap.GetPropertyMaps() .SingleOrDefault(m => m.DestinationProperty.Name == inheritedMappedProperty.DestinationProperty.Name); if (conventionPropertyMap != null && inheritedMappedProperty.HasCustomValueResolver) { conventionPropertyMap.AssignCustomValueResolver(inheritedMappedProperty.GetSourceValueResolvers().First()); } else if (conventionPropertyMap == null) { var propertyMap = new PropertyMap(inheritedMappedProperty.DestinationProperty); if (inheritedMappedProperty.IsIgnored()) { propertyMap.Ignore(); } else { foreach (var sourceValueResolver in inheritedMappedProperty.GetSourceValueResolvers()) { propertyMap.ChainResolver(sourceValueResolver); } } typeMap.AddInheritedPropertyMap(propertyMap); } } //Include BeforeMap if (inheritedTypeMap.BeforeMap != null) { typeMap.AddBeforeMapAction(inheritedTypeMap.BeforeMap); } //Include AfterMap if (inheritedTypeMap.AfterMap != null) { typeMap.AddAfterMapAction(inheritedTypeMap.AfterMap); } } }
private List <MemberBinding> CreateMemberBindings(ExpressionRequest request, TypeMap typeMap, Expression instanceParameter, Internal.IDictionary <ExpressionRequest, int> typePairCount) { var bindings = new List <MemberBinding>(); var visitCount = typePairCount.AddOrUpdate(request, 0, (tp, i) => i + 1); if (visitCount >= typeMap.MaxDepth) { return(bindings); } foreach (var propertyMap in typeMap.GetPropertyMaps().Where(pm => pm.CanResolveValue())) { var result = ResolveExpression(propertyMap, request.SourceType, instanceParameter); if (propertyMap.ExplicitExpansion && !request.IncludedMembers.Contains(propertyMap.DestinationProperty.Name)) { continue; } var propertyTypeMap = ConfigurationProvider.ResolveTypeMap(result.Type, propertyMap.DestinationPropertyType); var propertyRequest = new ExpressionRequest(result.Type, propertyMap.DestinationPropertyType, request.IncludedMembers); var binder = Binders.FirstOrDefault(b => b.IsMatch(propertyMap, propertyTypeMap, result)); if (binder == null) { var message = $"Unable to create a map expression from {propertyMap.SourceMember?.DeclaringType?.Name}.{propertyMap.SourceMember?.Name} ({result.Type}) to {propertyMap.DestinationProperty.MemberInfo.DeclaringType?.Name}.{propertyMap.DestinationProperty.Name} ({propertyMap.DestinationPropertyType})"; throw new AutoMapperMappingException(message); } var bindExpression = binder.Build(this, propertyMap, propertyTypeMap, propertyRequest, result, typePairCount); bindings.Add(bindExpression); } return(bindings); }
private void ApplyInheritedTypeMap(TypeMap inheritedTypeMap) { foreach (var inheritedMappedProperty in inheritedTypeMap.GetPropertyMaps().Where(m => m.IsMapped())) { var conventionPropertyMap = GetPropertyMaps() .SingleOrDefault(m => m.DestinationProperty.Name == inheritedMappedProperty.DestinationProperty.Name); if (conventionPropertyMap != null) { conventionPropertyMap.ApplyInheritedPropertyMap(inheritedMappedProperty); } else { var propertyMap = new PropertyMap(inheritedMappedProperty, this); _inheritedMaps.Add(propertyMap); } } //Include BeforeMap foreach (var beforeMapAction in inheritedTypeMap._beforeMapActions) { AddBeforeMapAction(beforeMapAction); } //Include AfterMap foreach (var afterMapAction in inheritedTypeMap._afterMapActions) { AddAfterMapAction(afterMapAction); } var notOverridenSourceConfigs = inheritedTypeMap._sourceMemberConfigs.Where( baseConfig => _sourceMemberConfigs.All(derivedConfig => derivedConfig.SourceMember != baseConfig.SourceMember)); _sourceMemberConfigs.AddRange(notOverridenSourceConfigs); var notOverridenPathMaps = inheritedTypeMap.PathMaps.Where( baseConfig => PathMaps.All(derivedConfig => derivedConfig.MemberPath != baseConfig.MemberPath)); _pathMaps.AddRange(notOverridenPathMaps); }
private void ApplyInheritedTypeMap(TypeMap inheritedTypeMap) { foreach (var inheritedMappedProperty in inheritedTypeMap.GetPropertyMaps().Where(m => m.IsMapped())) { var conventionPropertyMap = GetPropertyMaps() .SingleOrDefault(m => m.DestinationProperty.Name == inheritedMappedProperty.DestinationProperty.Name); if (conventionPropertyMap != null && inheritedMappedProperty.HasCustomValueResolver && !conventionPropertyMap.HasCustomValueResolver) { conventionPropertyMap.AssignCustomValueResolver( inheritedMappedProperty.GetSourceValueResolvers().First()); conventionPropertyMap.AssignCustomExpression(inheritedMappedProperty.CustomExpression); } else if (conventionPropertyMap == null) { var propertyMap = new PropertyMap(inheritedMappedProperty); AddInheritedPropertyMap(propertyMap); } } //Include BeforeMap if (inheritedTypeMap.BeforeMap != null) AddBeforeMapAction(inheritedTypeMap.BeforeMap); //Include AfterMap if (inheritedTypeMap.AfterMap != null) AddAfterMapAction(inheritedTypeMap.AfterMap); }
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 ApplyInheritedTypeMap(TypeMap inheritedTypeMap) { foreach (var inheritedMappedProperty in inheritedTypeMap.GetPropertyMaps().Where(m => m.IsMapped())) { var conventionPropertyMap = GetPropertyMaps() .SingleOrDefault(m => m.DestinationProperty.Name == inheritedMappedProperty.DestinationProperty.Name); if (conventionPropertyMap != null) { conventionPropertyMap.ApplyInheritedPropertyMap(inheritedMappedProperty); } else { var propertyMap = new PropertyMap(inheritedMappedProperty, this); _inheritedMaps.Add(propertyMap); } } //Include BeforeMap foreach (var beforeMapAction in inheritedTypeMap._beforeMapActions) { AddBeforeMapAction(beforeMapAction); } //Include AfterMap foreach (var afterMapAction in inheritedTypeMap._afterMapActions) { AddAfterMapAction(afterMapAction); } }
private void CheckPropertyMaps(ICollection<TypeMap> typeMapsChecked, TypeMap typeMap, ResolutionContext context) { foreach (var propertyMap in typeMap.GetPropertyMaps()) { if (propertyMap.Ignored) continue; var sourceType = propertyMap.SourceType; if (sourceType == null) continue; // when we don't know what the source type is, bail if (sourceType.IsGenericParameter || sourceType == typeof (object)) return; var destinationType = propertyMap.DestinationProperty.GetMemberType(); var memberTypeMap = _config.ResolveTypeMap(sourceType, destinationType); if (typeMapsChecked.Any(tm => Equals(tm, memberTypeMap))) continue; DryRunTypeMap(typeMapsChecked, new TypePair(sourceType, destinationType), memberTypeMap, context); } }