Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
667a3d5
use Enum.Parse<TEnum>
lbargaoanu Jul 30, 2022
77086e8
less allocations
lbargaoanu Jul 31, 2022
e3aecd3
reuse the execution plan between user Map calls and internal Map calls
lbargaoanu Aug 1, 2022
6581906
remove IObjectMapperInfo
lbargaoanu Aug 2, 2022
5f0cebd
use the more efficient Expression.Invoke instead of ConvertReplacePar…
lbargaoanu Aug 3, 2022
9fc7cdf
less allocations
lbargaoanu Aug 3, 2022
7fdf915
less null checks
lbargaoanu Aug 4, 2022
4b507ee
unreachable, As maps are sealed by default
lbargaoanu Aug 6, 2022
84e3fff
less allocations
lbargaoanu Aug 6, 2022
b5cc0a6
don't try to match ignored members
lbargaoanu Aug 7, 2022
df48e72
more efficient
lbargaoanu Aug 7, 2022
12eaef9
drop RegEx
lbargaoanu Aug 8, 2022
06b0713
docs
lbargaoanu Aug 8, 2022
dc7e58f
cosmetic
lbargaoanu Aug 8, 2022
9356388
less allocations
lbargaoanu Aug 8, 2022
39fccd9
cosmetic
lbargaoanu Aug 9, 2022
a3ae964
less allocations
lbargaoanu Aug 9, 2022
00d29ee
we don't need to create As type maps
lbargaoanu Aug 11, 2022
c9bceef
remove ITypeMapConfiguration
lbargaoanu Aug 11, 2022
a0988d7
cosmetic
lbargaoanu Aug 11, 2022
0b9cf8c
try to show a better error message when mapping records through const…
lbargaoanu Aug 11, 2022
b9699dd
less allocations
lbargaoanu Aug 13, 2022
ed9097f
special case the defaults for naming conventions
lbargaoanu Aug 13, 2022
93576ef
make TypeMapPlanBuilder a struct
lbargaoanu Aug 15, 2022
3adb02f
use readonly record struct
lbargaoanu Aug 15, 2022
7720ac8
assume that a protected constructor with CompilerGeneratedAttribute m…
lbargaoanu Aug 15, 2022
4e1117f
less allocations
lbargaoanu Aug 15, 2022
dac3062
rename configurationProvider to the shorter configuration in most places
lbargaoanu Aug 17, 2022
b24560f
less allocations
lbargaoanu Aug 17, 2022
953d66d
converters with no source should throw
lbargaoanu Aug 17, 2022
ebd2c43
less allocations
lbargaoanu Aug 18, 2022
c5d7c36
cosmetic
lbargaoanu Aug 18, 2022
12676dd
less allocations
lbargaoanu Aug 19, 2022
85ff705
make MapFrom name more like the built-in mapping
lbargaoanu Aug 19, 2022
c71f168
less allocations
lbargaoanu Aug 20, 2022
3de255f
cosmetic
lbargaoanu Aug 21, 2022
6925737
use profiles in the benchmark
lbargaoanu Aug 21, 2022
08ec72a
simplify conventions
lbargaoanu Aug 21, 2022
e9287a2
merge the profile member configuration with the global one
lbargaoanu Aug 21, 2022
0d2aa50
cosmetic
lbargaoanu Aug 22, 2022
ec0a832
test reusing the execution plan
lbargaoanu Aug 22, 2022
593ad53
refactor test base classes
lbargaoanu Aug 22, 2022
806e73f
cosmetic
lbargaoanu Aug 23, 2022
d0e0e24
avoid changing the resolver configuration objects because they're reu…
lbargaoanu Aug 31, 2022
77e0015
cosmetic
lbargaoanu Aug 31, 2022
20c283a
less allocations
lbargaoanu Sep 3, 2022
66f0020
cosmetic
lbargaoanu Sep 3, 2022
f1655e1
file scoped namespaces
lbargaoanu Sep 3, 2022
288c4ad
global usings
lbargaoanu Sep 3, 2022
e6f2ca3
cosmetic
lbargaoanu Sep 4, 2022
daacd80
less allocations
lbargaoanu Sep 10, 2022
c608787
NullMappingOrderComesFirst
lbargaoanu Sep 10, 2022
434703c
less allocations
lbargaoanu Sep 10, 2022
4ba0e5f
we could include a different constructor
lbargaoanu Sep 10, 2022
b98273e
less allocations
lbargaoanu Sep 10, 2022
7eeaf59
cosmetic
lbargaoanu Sep 11, 2022
efd1df9
allocate _runtimeTypeDetails lazily
lbargaoanu Sep 12, 2022
3a491a3
create the projection builder lazily
lbargaoanu Sep 12, 2022
7da36f6
cosmetic
lbargaoanu Sep 12, 2022
970ab2d
an adhoc fix for including open generic config
lbargaoanu Sep 14, 2022
e7ba023
cosmetic
lbargaoanu Sep 18, 2022
2b99e96
MapFrom should override ignore
lbargaoanu Sep 18, 2022
3f8448a
UseDestinationValueNullable
lbargaoanu Sep 19, 2022
8b83aa7
cosmetic
lbargaoanu Sep 21, 2022
5e0066e
avoid LINQ
lbargaoanu Sep 23, 2022
7d65b78
the destination type name is already in the error message
lbargaoanu Sep 24, 2022
3c2d8cd
cosmetic
lbargaoanu Sep 24, 2022
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
Prev Previous commit
Next Next commit
cosmetic
  • Loading branch information
lbargaoanu committed Sep 13, 2022
commit 7da36f6435e9de3eb498de48c7422e91c04314d2
3 changes: 2 additions & 1 deletion src/AutoMapper/ApiCompatBaseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ MembersMustExist : Member 'public System.Type System.Type AutoMapper.ValueTransf
InterfacesShouldHaveSameMembers : Default interface member 'public System.Boolean AutoMapper.Configuration.IPropertyMapConfiguration.Ignored' is present in the implementation but not in the contract.
InterfacesShouldHaveSameMembers : Default interface member 'public System.Boolean AutoMapper.Configuration.IPropertyMapConfiguration.Ignored.get()' is present in the implementation but not in the contract.
CannotRemoveBaseTypeOrInterface : Type 'AutoMapper.Configuration.MappingExpression' does not inherit from base type 'AutoMapper.Configuration.MappingExpressionBase' in the implementation but it does in the contract.
TypesMustExist : Type 'AutoMapper.Configuration.MappingExpression.MemberConfigurationExpression' does not exist in the implementation but it does exist in the contract.
CannotRemoveBaseTypeOrInterface : Type 'AutoMapper.Configuration.MappingExpression<TSource, TDestination>' does not inherit from base type 'AutoMapper.Configuration.MappingExpressionBase' in the implementation but it does in the contract.
TypesMustExist : Type 'AutoMapper.Configuration.MappingExpressionBase' does not exist in the implementation but it does exist in the contract.
CannotRemoveBaseTypeOrInterface : Type 'AutoMapper.Configuration.MappingExpressionBase<TSource, TDestination, TMappingExpression>' does not inherit from base type 'AutoMapper.Configuration.MappingExpressionBase' in the implementation but it does in the contract.
Expand Down Expand Up @@ -121,4 +122,4 @@ MembersMustExist : Member 'public AutoMapper.Internal.TypePair AutoMapper.Intern
MembersMustExist : Member 'public System.Linq.IQueryable<TDestination> AutoMapper.QueryableExtensions.Extensions.Map<TSource, TDestination>(System.Linq.IQueryable<TSource>, System.Linq.IQueryable<TDestination>, AutoMapper.IConfigurationProvider)' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Collections.Generic.IReadOnlyCollection<System.Reflection.MemberInfo> AutoMapper.QueryableExtensions.MemberVisitor.MemberPath.get()' does not exist in the implementation but it does exist in the contract.
TypesMustExist : Type 'AutoMapper.QueryableExtensions.Impl.MemberAccessQueryMapperVisitor' does not exist in the implementation but it does exist in the contract.
Total Issues: 122
Total Issues: 123
1 change: 0 additions & 1 deletion src/AutoMapper/Configuration/Conventions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
namespace AutoMapper.Configuration.Conventions;

public interface ISourceToDestinationNameMapper
{
MemberInfo GetSourceMember(TypeDetails sourceTypeDetails, Type destType, Type destMemberType, string nameToSearch);
Expand Down
26 changes: 12 additions & 14 deletions src/AutoMapper/Configuration/MapperConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class MapperConfiguration : IGlobalConfiguration
private readonly Dictionary<TypePair, TypeMap> _configuredMaps;
private readonly Dictionary<TypePair, TypeMap> _resolvedMaps;
private readonly LockingConcurrentDictionary<TypePair, TypeMap> _runtimeMaps;
private ProjectionBuilder _projectionBuilder;
private LazyValue<ProjectionBuilder> _projectionBuilder;
private readonly LockingConcurrentDictionary<MapRequest, Delegate> _executionPlans;
private readonly ConfigurationValidator _validator;
private readonly Features<IRuntimeFeature> _features = new();
Expand Down Expand Up @@ -74,6 +74,7 @@ public MapperConfiguration(MapperConfigurationExpression configurationExpression
_serviceCtor = configuration.ServiceCtor;
_enableNullPropagationForQueryMapping = configuration.EnableNullPropagationForQueryMapping ?? false;
_maxExecutionPlanDepth = configuration.MaxExecutionPlanDepth + 1;
_projectionBuilder = new(CreateProjectionBuilder);
_recursiveQueriesMaxDepth = configuration.RecursiveQueriesMaxDepth;
Configuration = new((IProfileConfiguration)configuration);
int typeMapsCount = Configuration.TypeMapsCount;
Expand Down Expand Up @@ -232,18 +233,8 @@ LambdaExpression GenerateObjectMapperExpression(in MapRequest mapRequest, IObjec
return Lambda(fullExpression, source, destination, ContextParameter);
}
}
IProjectionBuilder IGlobalConfiguration.ProjectionBuilder
{
get
{
if (_projectionBuilder == null)
{
CreateProjectionBuilder();
}
return _projectionBuilder;
void CreateProjectionBuilder() => Interlocked.CompareExchange(ref _projectionBuilder, new(this, _validator.Expression.ProjectionMappers.ToArray()), null);
}
}
ProjectionBuilder CreateProjectionBuilder() => new(this, _validator.Expression.ProjectionMappers.ToArray());
IProjectionBuilder IGlobalConfiguration.ProjectionBuilder => _projectionBuilder.Value;
Func<Type, object> IGlobalConfiguration.ServiceCtor => _serviceCtor;
bool IGlobalConfiguration.EnableNullPropagationForQueryMapping => _enableNullPropagationForQueryMapping;
int IGlobalConfiguration.MaxExecutionPlanDepth => _maxExecutionPlanDepth;
Expand Down Expand Up @@ -493,7 +484,7 @@ IObjectMapper FindMapper(TypePair types)
void IGlobalConfiguration.AssertConfigurationIsValid(TypeMap typeMap) => _validator.AssertConfigurationIsValid(this, new[] { typeMap });
void IGlobalConfiguration.AssertConfigurationIsValid(string profileName)
{
if (Profiles.All(x => x.Name != profileName))
if (Array.TrueForAll(Profiles, x => x.Name != profileName))
{
throw new ArgumentOutOfRangeException(nameof(profileName), $"Cannot find any profiles with the name '{profileName}'.");
}
Expand All @@ -502,4 +493,11 @@ void IGlobalConfiguration.AssertConfigurationIsValid(string profileName)
void IGlobalConfiguration.AssertConfigurationIsValid<TProfile>() => this.Internal().AssertConfigurationIsValid(typeof(TProfile).FullName);
void IGlobalConfiguration.RegisterAsMap(TypeMapConfiguration typeMapConfiguration) =>
_resolvedMaps[typeMapConfiguration.Types] = GetIncludedTypeMap(new(typeMapConfiguration.SourceType, typeMapConfiguration.DestinationTypeOverride));
}
struct LazyValue<T> where T : class
{
readonly Func<T> _factory;
T _value = null;
public T Value => LazyInitializer.EnsureInitialized(ref _value, _factory);
public LazyValue(Func<T> factory) => _factory = factory;
}
27 changes: 0 additions & 27 deletions src/AutoMapper/Configuration/MappingExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,33 +52,6 @@ internal MemberConfigurationExpression ForMember(MemberInfo destinationProperty,
memberOptions(expression);
return expression;
}
public class MemberConfigurationExpression : MemberConfigurationExpression<object, object, object>, IMemberConfigurationExpression
{
public MemberConfigurationExpression(MemberInfo destinationMember, Type sourceType) : base(destinationMember, sourceType){}
public void MapFrom(Type valueResolverType) => MapFromCore(new(valueResolverType, valueResolverType.GetGenericInterface(typeof(IValueResolver<,,>))));
public void MapFrom(Type valueResolverType, string sourceMemberName) =>
MapFromCore(new(valueResolverType, valueResolverType.GetGenericInterface(typeof(IMemberValueResolver<,,,>)))
{
SourceMemberName = sourceMemberName
});
public void MapFrom<TSource, TDestination, TSourceMember, TDestMember>(IMemberValueResolver<TSource, TDestination, TSourceMember, TDestMember> resolver, string sourceMemberName) =>
MapFromCore(new(resolver, typeof(IMemberValueResolver<TSource, TDestination, TSourceMember, TDestMember>))
{
SourceMemberName = sourceMemberName
});
public void ConvertUsing(Type valueConverterType) => ConvertUsingCore(valueConverterType);
public void ConvertUsing(Type valueConverterType, string sourceMemberName) => ConvertUsingCore(valueConverterType, sourceMemberName);
public void ConvertUsing<TSourceMember, TDestinationMember>(IValueConverter<TSourceMember, TDestinationMember> valueConverter, string sourceMemberName) =>
base.ConvertUsingCore(new(valueConverter, typeof(IValueConverter<TSourceMember, TDestinationMember>))
{
SourceMemberName = sourceMemberName
});
private void ConvertUsingCore(Type valueConverterType, string sourceMemberName = null) =>
base.ConvertUsingCore(new(valueConverterType, valueConverterType.GetGenericInterface(typeof(IValueConverter<,>)))
{
SourceMemberName = sourceMemberName
});
}
}
public class MappingExpression<TSource, TDestination> : MappingExpressionBase<TSource, TDestination, IMappingExpression<TSource, TDestination>>,
IMappingExpression<TSource, TDestination>, IProjectionExpression<TSource, TDestination>
Expand Down
27 changes: 27 additions & 0 deletions src/AutoMapper/Configuration/MemberConfigurationExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,31 @@ public IPropertyMapConfiguration Reverse()
return PathConfigurationExpression<TDestination, TSource, object>.Create(SourceExpression, GetDestinationExpression());
}
public void DoNotUseDestinationValue() => SetUseDestinationValue(false);
}
public class MemberConfigurationExpression : MemberConfigurationExpression<object, object, object>, IMemberConfigurationExpression
{
public MemberConfigurationExpression(MemberInfo destinationMember, Type sourceType) : base(destinationMember, sourceType){}
public void MapFrom(Type valueResolverType) => MapFromCore(new(valueResolverType, valueResolverType.GetGenericInterface(typeof(IValueResolver<,,>))));
public void MapFrom(Type valueResolverType, string sourceMemberName) =>
MapFromCore(new(valueResolverType, valueResolverType.GetGenericInterface(typeof(IMemberValueResolver<,,,>)))
{
SourceMemberName = sourceMemberName
});
public void MapFrom<TSource, TDestination, TSourceMember, TDestMember>(IMemberValueResolver<TSource, TDestination, TSourceMember, TDestMember> resolver, string sourceMemberName) =>
MapFromCore(new(resolver, typeof(IMemberValueResolver<TSource, TDestination, TSourceMember, TDestMember>))
{
SourceMemberName = sourceMemberName
});
public void ConvertUsing(Type valueConverterType) => ConvertUsingCore(valueConverterType);
public void ConvertUsing(Type valueConverterType, string sourceMemberName) => ConvertUsingCore(valueConverterType, sourceMemberName);
public void ConvertUsing<TSourceMember, TDestinationMember>(IValueConverter<TSourceMember, TDestinationMember> valueConverter, string sourceMemberName) =>
base.ConvertUsingCore(new(valueConverter, typeof(IValueConverter<TSourceMember, TDestinationMember>))
{
SourceMemberName = sourceMemberName
});
private void ConvertUsingCore(Type valueConverterType, string sourceMemberName = null) =>
base.ConvertUsingCore(new(valueConverterType, valueConverterType.GetGenericInterface(typeof(IValueConverter<,>)))
{
SourceMemberName = sourceMemberName
});
}
3 changes: 1 addition & 2 deletions src/AutoMapper/Features.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections;
namespace AutoMapper.Features;
namespace AutoMapper.Features;
public interface IGlobalFeature
{
void Configure(IGlobalConfiguration configuration);
Expand Down
15 changes: 4 additions & 11 deletions src/AutoMapper/ProfileMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ProfileMap
private TypeMapConfiguration[] _typeMapConfigs;
private Dictionary<TypePair, TypeMapConfiguration> _openTypeMapConfigs;
private Dictionary<Type, TypeDetails> _typeDetails;
private ConcurrentDictionary<Type, TypeDetails> _runtimeTypeDetails;
private LazyValue<ConcurrentDictionary<Type, TypeDetails>> _runtimeTypeDetails;
public ProfileMap(IProfileConfiguration profile, IGlobalConfigurationExpression configuration = null)
{
var globalProfile = (IProfileConfiguration)configuration;
Expand Down Expand Up @@ -39,6 +39,7 @@ public ProfileMap(IProfileConfiguration profile, IGlobalConfigurationExpression
TypeMapConfigs();
OpenTypeMapConfigs();
_typeDetails = new(2 * _typeMapConfigs.Length);
_runtimeTypeDetails = new(()=>new(Environment.ProcessorCount, 2 * _openTypeMapConfigs.Count));
return;
void TypeMapConfigs()
{
Expand Down Expand Up @@ -99,7 +100,7 @@ public TypeDetails CreateTypeDetails(Type type)
{
if (_typeDetails == null)
{
return CreateRuntimeTypeDetails(type);
return _runtimeTypeDetails.Value.GetOrAdd(type, (type, profile) => new(type, profile), this);
}
if (_typeDetails.TryGetValue(type, out var typeDetails))
{
Expand All @@ -108,14 +109,6 @@ public TypeDetails CreateTypeDetails(Type type)
typeDetails = new(type, this);
_typeDetails.Add(type, typeDetails);
return typeDetails;
TypeDetails CreateRuntimeTypeDetails(Type type)
{
if (_runtimeTypeDetails == null)
{
Interlocked.CompareExchange(ref _runtimeTypeDetails, new(Environment.ProcessorCount, 2 * _openTypeMapConfigs.Count), null);
}
return _runtimeTypeDetails.GetOrAdd(type, (type, profile) => new(type, profile), this);
}
}
public void Register(IGlobalConfiguration configuration)
{
Expand Down Expand Up @@ -187,7 +180,7 @@ private void Configure(TypeMap typeMap, IGlobalConfiguration configuration)
{
foreach (var propertyMap in typeMap.PropertyMaps)
{
var memberExpression = new MappingExpression.MemberConfigurationExpression(propertyMap.DestinationMember, typeMap.SourceType);
var memberExpression = new MemberConfigurationExpression(propertyMap.DestinationMember, typeMap.SourceType);
action(propertyMap, memberExpression);
memberExpression.Configure(typeMap);
}
Expand Down
6 changes: 6 additions & 0 deletions src/UnitTests/Projection/ProjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public class FooDto
public void Should_work()
{
new[] { new Foo() }.AsQueryable().ProjectTo<FooDto>(Configuration).Single().A.ShouldBe(0);

var p1 = Configuration.Internal().ProjectionBuilder;
var p2 = Configuration.Internal().ProjectionBuilder;
p2.ShouldBe(p1);
var profile = Configuration.Internal().Profiles[0];
profile.CreateTypeDetails(typeof(DateTime)).ShouldBe(profile.CreateTypeDetails(typeof(DateTime)));
}
}

Expand Down