Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void CreateProfile(string profileName, Action<IProfileExpression> config)

public AdvancedConfiguration Advanced { get; } = new AdvancedConfiguration();

public GlobalFeatures Features { get; } = new GlobalFeatures();
public Features<IGlobalFeature> Features { get; } = new Features<IGlobalFeature>();

private class NamedProfile : Profile
{
Expand Down
2 changes: 1 addition & 1 deletion src/AutoMapper/Configuration/MappingExpressionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected MappingExpressionBase(MemberList memberList, TypePair types)
public bool IsOpenGeneric { get; }
public Type SourceType => Types.SourceType;
public Type DestinationType => Types.DestinationType;
public MappingFeatures Features { get; } = new MappingFeatures();
public Features<IMappingFeature> Features { get; } = new Features<IMappingFeature>();
public ITypeMapConfiguration ReverseTypeMap => ReverseMapExpression;
public IList<ValueTransformerConfiguration> ValueTransformers { get; } = new List<ValueTransformerConfiguration>();

Expand Down
8 changes: 8 additions & 0 deletions src/AutoMapper/Configuration/PrimitiveExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ namespace AutoMapper.Configuration
{
internal static class PrimitiveExtensions
{
public static void ForAll<T>(this IEnumerable<T> enumerable, Action<T> action)
{
foreach (var feature in enumerable)
{
action(feature);
}
}

public static bool IsSetType(this Type type)
=> type.ImplementsGenericInterface(typeof(ISet<>));

Expand Down
38 changes: 38 additions & 0 deletions src/AutoMapper/Features/FeatureExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using AutoMapper.Configuration;

namespace AutoMapper.Features
{
public static class FeatureExtensions
{
public static IMapperConfigurationExpression SetFeature(this IMapperConfigurationExpression configuration, IGlobalFeature feature)
{
configuration.Features.Set(feature);
return configuration;
}

public static IMappingExpression<TSource, TDestination> SetFeature<TSource, TDestination>(this IMappingExpression<TSource, TDestination> mapping, IMappingFeature feature)
{
mapping.Features.Set(feature);
return mapping;
}

internal static void Configure(this Features<IGlobalFeature> features, MapperConfiguration mapperConfiguration) => features.ForAll(feature => feature.Configure(mapperConfiguration));

public static void ReverseTo(this Features<IMappingFeature> features, Features<IMappingFeature> reversedFeatures) => features.ForAll(feature =>
{
var reverse = feature.Reverse();
if (reverse != null)
{
reversedFeatures.Set(reverse);
}
});

internal static void Configure(this Features<IMappingFeature> features, TypeMap typeMap) => features.ForAll(feature => feature.Configure(typeMap));

internal static void Seal(this Features<IRuntimeFeature> features, IConfigurationProvider configurationProvider)
{
features.ForAll(feature => feature.Seal(configurationProvider));
features.MakeReadOnly();
}
}
}
10 changes: 1 addition & 9 deletions src/AutoMapper/Features/Features.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ public class Features<TFeature> : IEnumerable<TFeature>

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

protected void MakeReadOnly() => _features = new ReadOnlyDictionary<Type, TFeature>(_features);

public void ForAll(Action<TFeature> action)
{
foreach (var feature in this)
{
action(feature);
}
}
internal void MakeReadOnly() => _features = new ReadOnlyDictionary<Type, TFeature>(_features);
}
}
7 changes: 0 additions & 7 deletions src/AutoMapper/Features/GlobalFeatures.cs

This file was deleted.

17 changes: 1 addition & 16 deletions src/AutoMapper/Features/IRuntimeFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,4 @@ public interface IRuntimeFeature
{
void Seal(IConfigurationProvider configurationProvider);
}

public static class FeatureExtensions
{
public static IMapperConfigurationExpression AddOrUpdateFeature(this IMapperConfigurationExpression configuration, IGlobalFeature feature)
{
configuration.Features.Set(feature);
return configuration;
}

public static IMappingExpression<TSource, TDestination> AddOrUpdateFeature<TSource, TDestination>(this IMappingExpression<TSource, TDestination> mapping, IMappingFeature feature)
{
mapping.Features.Set(feature);
return mapping;
}
}
}
}
16 changes: 0 additions & 16 deletions src/AutoMapper/Features/MappingFeatures.cs

This file was deleted.

11 changes: 0 additions & 11 deletions src/AutoMapper/Features/RuntimeFeatures.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/AutoMapper/IConfigurationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public interface IConfigurationProvider
/// Gets the features collection.
/// </summary>
/// <value>The feature colection.</value>
RuntimeFeatures Features { get; }
Features<IRuntimeFeature> Features { get; }

/// <summary>
/// Find a matching object mapper.
Expand Down
2 changes: 1 addition & 1 deletion src/AutoMapper/IMapperConfigurationExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public interface IMapperConfigurationExpression : IProfileExpression
/// <summary>
/// Get the features collection.
/// </summary>
GlobalFeatures Features { get; }
Features<IGlobalFeature> Features { get; }

/// <summary>
/// Object mappers
Expand Down
2 changes: 1 addition & 1 deletion src/AutoMapper/IMappingExpressionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace AutoMapper
public interface IMappingExpressionBase<TSource, TDestination, out TMappingExpression>
where TMappingExpression : IMappingExpressionBase<TSource, TDestination, TMappingExpression>
{
MappingFeatures Features { get; }
Features<IMappingFeature> Features { get; }

/// <summary>
/// Construct the destination object using the service locator
Expand Down
2 changes: 1 addition & 1 deletion src/AutoMapper/MapperConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void Validate(ValidationContext context)

public IEnumerable<IExpressionBinder> Binders { get; }

public RuntimeFeatures Features { get; } = new RuntimeFeatures();
public Features<IRuntimeFeature> Features { get; } = new Features<IRuntimeFeature>();

public Func<TSource, TDestination, ResolutionContext, TDestination> GetMapperFunc<TSource, TDestination>(
TypePair types, IMemberMap memberMap = null)
Expand Down
2 changes: 1 addition & 1 deletion src/AutoMapper/TypeMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public PathMap FindOrCreatePathMapFor(LambdaExpression destinationExpression, Me

private void AddPathMap(PathMap pathMap) => _pathMaps.Add(pathMap.MemberPath, pathMap);

public RuntimeFeatures Features { get; } = new RuntimeFeatures();
public Features<IRuntimeFeature> Features { get; } = new Features<IRuntimeFeature>();

public PathMap FindPathMapByDestinationPath(string destinationFullPath) =>
PathMaps.SingleOrDefault(item => string.Join(".", item.MemberPath.Members.Select(m => m.Name)) == destinationFullPath);
Expand Down
18 changes: 9 additions & 9 deletions src/UnitTests/ConfigurationFeatureTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public void Adding_same_feature_multiple_times_should_replace_eachother()
var featureB = new ConfigurationExpressionFeatureB(1);
var config = new MapperConfiguration(cfg =>
{
cfg.AddOrUpdateFeature(new ConfigurationExpressionFeatureA(3));
cfg.AddOrUpdateFeature(new ConfigurationExpressionFeatureA(2));
cfg.AddOrUpdateFeature(featureA);
cfg.AddOrUpdateFeature(new ConfigurationExpressionFeatureB(3));
cfg.AddOrUpdateFeature(new ConfigurationExpressionFeatureB(2));
cfg.AddOrUpdateFeature(featureB);
cfg.SetFeature(new ConfigurationExpressionFeatureA(3));
cfg.SetFeature(new ConfigurationExpressionFeatureA(2));
cfg.SetFeature(featureA);
cfg.SetFeature(new ConfigurationExpressionFeatureB(3));
cfg.SetFeature(new ConfigurationExpressionFeatureB(2));
cfg.SetFeature(featureB);
});

Validate<ConfigurationFeatureA>(featureA, config);
Expand All @@ -32,7 +32,7 @@ public void Add_single_feature()
var featureA = new ConfigurationExpressionFeatureA(1);
var config = new MapperConfiguration(cfg =>
{
cfg.AddOrUpdateFeature(featureA);
cfg.SetFeature(featureA);
});

Validate<ConfigurationFeatureA>(featureA, config);
Expand All @@ -45,8 +45,8 @@ public void Add_multiple_features()
var featureB = new ConfigurationExpressionFeatureB(2);
var config = new MapperConfiguration(cfg =>
{
cfg.AddOrUpdateFeature(featureA);
cfg.AddOrUpdateFeature(featureB);
cfg.SetFeature(featureA);
cfg.SetFeature(featureB);
});

Validate<ConfigurationFeatureA>(featureA, config);
Expand Down
24 changes: 12 additions & 12 deletions src/UnitTests/MappingExpressionFeatureWithReverseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public void Adding_same_feature_multiple_times_should_replace_eachother()
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<Source, Dest>()
.AddOrUpdateFeature(new MappingExpressionFeatureA(3))
.AddOrUpdateFeature(new MappingExpressionFeatureA(2))
.AddOrUpdateFeature(featureA)
.AddOrUpdateFeature(new MappingExpressionFeatureB(3))
.AddOrUpdateFeature(new MappingExpressionFeatureB(2))
.AddOrUpdateFeature(featureB)
.SetFeature(new MappingExpressionFeatureA(3))
.SetFeature(new MappingExpressionFeatureA(2))
.SetFeature(featureA)
.SetFeature(new MappingExpressionFeatureB(3))
.SetFeature(new MappingExpressionFeatureB(2))
.SetFeature(featureB)
.ReverseMap();
});

Expand Down Expand Up @@ -50,7 +50,7 @@ public void Add_single_feature_with_reverse()
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<Source, Dest>()
.AddOrUpdateFeature(featureA)
.SetFeature(featureA)
.ReverseMap();
});

Expand Down Expand Up @@ -88,8 +88,8 @@ public void Add_multiple_features_with_reverse()
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<Source, Dest>()
.AddOrUpdateFeature(featureA)
.AddOrUpdateFeature(featureB)
.SetFeature(featureA)
.SetFeature(featureB)
.ReverseMap();
});

Expand Down Expand Up @@ -129,10 +129,10 @@ public void Add_multiple_features_with_reverse_overriden()
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<Source, Dest>()
.AddOrUpdateFeature(featureA)
.AddOrUpdateFeature(featureB)
.SetFeature(featureA)
.SetFeature(featureB)
.ReverseMap()
.AddOrUpdateFeature(overridenFeatureB);
.SetFeature(overridenFeatureB);
});

var typeMap = config.FindTypeMapFor<Source, Dest>();
Expand Down
30 changes: 15 additions & 15 deletions src/UnitTests/MappingExpressionFeatureWithoutReverseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public void Adding_same_feature_should_replace_eachother()
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<Source, Dest>()
.AddOrUpdateFeature(new MappingExpressionFeatureA(3))
.AddOrUpdateFeature(new MappingExpressionFeatureA(2))
.AddOrUpdateFeature(featureA)
.AddOrUpdateFeature(new MappingExpressionFeatureB(3))
.AddOrUpdateFeature(new MappingExpressionFeatureB(2))
.AddOrUpdateFeature(featureB);
.SetFeature(new MappingExpressionFeatureA(3))
.SetFeature(new MappingExpressionFeatureA(2))
.SetFeature(featureA)
.SetFeature(new MappingExpressionFeatureB(3))
.SetFeature(new MappingExpressionFeatureB(2))
.SetFeature(featureB);
});


Expand All @@ -48,7 +48,7 @@ public void Add_single_feature()
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<Source, Dest>()
.AddOrUpdateFeature(featureA);
.SetFeature(featureA);
});

var typeMap = config.FindTypeMapFor<Source, Dest>();
Expand Down Expand Up @@ -79,7 +79,7 @@ public void Add_single_feature_with_reverse()
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<Source, Dest>()
.AddOrUpdateFeature(featureA)
.SetFeature(featureA)
.ReverseMap();
});

Expand Down Expand Up @@ -112,8 +112,8 @@ public void Add_multiple_features()
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<Source, Dest>()
.AddOrUpdateFeature(featureA)
.AddOrUpdateFeature(featureB);
.SetFeature(featureA)
.SetFeature(featureB);
});


Expand Down Expand Up @@ -147,8 +147,8 @@ public void Add_multiple_features_with_reverse()
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<Source, Dest>()
.AddOrUpdateFeature(featureA)
.AddOrUpdateFeature(featureB)
.SetFeature(featureA)
.SetFeature(featureB)
.ReverseMap();
});

Expand Down Expand Up @@ -183,10 +183,10 @@ public void Add_multiple_features_with_reverse_overriden()
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<Source, Dest>()
.AddOrUpdateFeature(featureA)
.AddOrUpdateFeature(featureB)
.SetFeature(featureA)
.SetFeature(featureB)
.ReverseMap()
.AddOrUpdateFeature(overridenFeatureB);
.SetFeature(overridenFeatureB);
});

var typeMap = config.FindTypeMapFor<Source, Dest>();
Expand Down