public IModelConfiguration <TModel> ForMember <TProperty>(Expression <Func <TModel, TProperty> > propExpression, Action <IMemberConfiguration <TModel, TProperty> > action) { var propName = propExpression.GetFullPropertyName(); var propInfo = ModelType.GetProperty(propName); if (propInfo == null) { throw new NullReferenceException(string.Format("Type '{0}' does not contain a property with name '{1}'.", ModelType, propName)); } IMemberConfiguration memberConfiguration; if (MemberConfigurations.ContainsKey(propName)) { memberConfiguration = MemberConfigurations[propName]; } else { memberConfiguration = new MemberConfiguration <TModel, TProperty>(propInfo); BreezeConfigurator.OnSerializationMemberRuleCreated(memberConfiguration); MemberConfigurations[propName] = memberConfiguration; } if (action != null) { action((IMemberConfiguration <TModel, TProperty>)memberConfiguration); } return(this); }
void IProfileConfiguration.Register(TypeMapRegistry typeMapRegistry) { Prefixes = MemberConfigurations .Select(m => m.NameMapper) .SelectMany(m => m.NamedMappers) .OfType <PrePostfixName>() .SelectMany(m => m.Prefixes) .ToArray(); Postfixes = MemberConfigurations .Select(m => m.NameMapper) .SelectMany(m => m.NamedMappers) .OfType <PrePostfixName>() .SelectMany(m => m.Postfixes) .ToArray(); foreach (var config in _typeMapConfigs.Where(c => !c.IsOpenGeneric)) { BuildTypeMap(typeMapRegistry, config); if (config.ReverseTypeMap != null) { BuildTypeMap(typeMapRegistry, config.ReverseTypeMap); } } }
public ITypeConfiguration <TType> ForMember <TProperty>(Expression <Func <TType, TProperty> > propExpression, Action <IFieldConfiguration <TType, TProperty> > action) { var propName = propExpression.GetFullPropertyName(); var propInfo = ModelType.GetProperty(propName); if (propInfo == null) { throw new NullReferenceException(string.Format("Type '{0}' does not contain a property with name '{1}'.", ModelType, propName)); } IFieldConfiguration fieldConfiguration; if (MemberConfigurations.ContainsKey(propName)) { fieldConfiguration = MemberConfigurations[propName]; } else { fieldConfiguration = new FieldConfiguration <TType, TProperty>(propInfo); MemberConfigurations[propName] = fieldConfiguration; } if (action != null) { action((IFieldConfiguration <TType, TProperty>)fieldConfiguration); } return(this); }
public bool MapDestinationPropertyToSource(TypeDetails sourceTypeInfo, Type destType, Type destMemberType, string destMemberInfo, LinkedList <MemberInfo> members, bool reverseNamingConventions) { if (string.IsNullOrEmpty(destMemberInfo)) { return(false); } return(MemberConfigurations.Any(memberConfig => memberConfig.MapDestinationPropertyToSource(this, sourceTypeInfo, destType, destMemberType, destMemberInfo, members, reverseNamingConventions))); }
public IMappingExpression ReverseMap() { var reverseMap = new MappingExpression(new TypePair(Types.DestinationType, Types.SourceType), MemberList.Source); reverseMap.MemberConfigurations.AddRange(MemberConfigurations.Select(m => m.Reverse()).Where(m => m != null)); ReverseMapExpression = reverseMap; return(reverseMap); }
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(); }
internal MemberConfigurationExpression ForMember(MemberInfo destinationProperty, Action <IMemberConfigurationExpression> memberOptions) { var expression = new MemberConfigurationExpression(destinationProperty, Types.SourceType); MemberConfigurations.Add(expression); memberOptions(expression); return(expression); }
public IMappingExpression ReverseMap() { var reversedTypes = new TypePair(Types.DestinationType, Types.SourceType); var reverseMap = new MappingExpression(reversedTypes, MemberList.None); if (!reversedTypes.IsGenericTypeDefinition) { reverseMap.MemberConfigurations.AddRange(MemberConfigurations.Select(m => m.Reverse()).Where(m => m != null)); } ReverseMapExpression = reverseMap; reverseMap.IncludeMembers(MapToSourceMembers().Select(m => m.DestinationMember.Name).ToArray()); foreach (var includedMemberName in IncludedMembersNames) { reverseMap.ForMember(includedMemberName, m => m.MapFrom(s => s)); } return(reverseMap); }
public IModelConfiguration <TModel> AddMember <TProperty>(string serializedName, Action <ICustomMemberConfiguration <TModel, TProperty> > action) { IMemberConfiguration memberConfiguration; if (MemberConfigurations.ContainsKey(serializedName)) { memberConfiguration = MemberConfigurations[serializedName]; } else { memberConfiguration = new MemberConfiguration <TModel, TProperty>(serializedName, typeof(TProperty), typeof(TModel)); BreezeConfigurator.OnSerializationMemberRuleCreated(memberConfiguration); MemberConfigurations[serializedName] = memberConfiguration; } action?.Invoke((ICustomMemberConfiguration <TModel, TProperty>)memberConfiguration); return(this); }
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(); 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(); }
protected IPropertyMapConfiguration GetDestinationMemberConfiguration(MemberInfo destinationMember) => MemberConfigurations.FirstOrDefault(m => m.DestinationMember.Name == destinationMember.Name);
protected IEnumerable <IPropertyMapConfiguration> MapToSourceMembers() => MemberConfigurations.Where(m => m.SourceExpression != null && m.SourceExpression.Body == m.SourceExpression.Parameters[0]);