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
remove ITypeMapConfiguration
  • Loading branch information
lbargaoanu committed Aug 11, 2022
commit c9bceefb7a71425b6931429720598036857612f7
13 changes: 11 additions & 2 deletions src/AutoMapper/ApiCompatBaseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ MembersMustExist : Member 'public System.String AutoMapper.INamingConvention.Rep
InterfacesShouldHaveSameMembers : Interface member 'public System.String[] AutoMapper.INamingConvention.Split(System.String)' is present in the implementation but not in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public System.Text.RegularExpressions.Regex AutoMapper.INamingConvention.SplittingExpression.get()' is present in the contract but not in the implementation.
MembersMustExist : Member 'public System.Text.RegularExpressions.Regex AutoMapper.INamingConvention.SplittingExpression.get()' does not exist in the implementation but it does exist in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public System.Collections.Generic.IReadOnlyCollection<AutoMapper.Configuration.TypeMapConfiguration> AutoMapper.IProfileConfiguration.OpenTypeMapConfigs.get()' is present in the implementation but not in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public System.Collections.Generic.IReadOnlyCollection<AutoMapper.Configuration.ITypeMapConfiguration> AutoMapper.IProfileConfiguration.OpenTypeMapConfigs.get()' is present in the contract but not in the implementation.
MembersMustExist : Member 'public System.Collections.Generic.IReadOnlyCollection<AutoMapper.Configuration.ITypeMapConfiguration> AutoMapper.IProfileConfiguration.OpenTypeMapConfigs.get()' does not exist in the implementation but it does exist in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public System.Collections.Generic.IReadOnlyCollection<AutoMapper.Configuration.TypeMapConfiguration> AutoMapper.IProfileConfiguration.TypeMapConfigs.get()' is present in the implementation but not in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public System.Collections.Generic.IReadOnlyCollection<AutoMapper.Configuration.ITypeMapConfiguration> AutoMapper.IProfileConfiguration.TypeMapConfigs.get()' is present in the contract but not in the implementation.
MembersMustExist : Member 'public System.Collections.Generic.IReadOnlyCollection<AutoMapper.Configuration.ITypeMapConfiguration> AutoMapper.IProfileConfiguration.TypeMapConfigs.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.String AutoMapper.LowerUnderscoreNamingConvention.ReplaceValue(System.Text.RegularExpressions.Match)' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Text.RegularExpressions.Regex AutoMapper.LowerUnderscoreNamingConvention.SplittingExpression.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.String AutoMapper.PascalCaseNamingConvention.ReplaceValue(System.Text.RegularExpressions.Match)' does not exist in the implementation but it does exist in the contract.
Expand All @@ -19,7 +25,10 @@ MembersMustExist : Member 'public AutoMapper.IMappingOperationOptions AutoMapper
TypesMustExist : Type 'AutoMapper.ValueResolverConfiguration' does not exist in the implementation but it does exist in the contract.
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.
MembersMustExist : Member 'public void AutoMapper.Configuration.MappingExpressionBase.Configure(AutoMapper.TypeMap)' does not exist in the implementation but it does exist 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.
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.
MembersMustExist : Member 'public void AutoMapper.Configuration.MappingExpressionBase<TSource, TDestination, TMappingExpression>.AsProxy()' does not exist in the implementation but it does exist in the contract.
CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'AutoMapper.Configuration.Annotations.IgnoreAttribute' changed from '[AttributeUsageAttribute(384)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Field | AttributeTargets.Property)]' in the implementation.
CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'AutoMapper.Configuration.Annotations.MapAtRuntimeAttribute' changed from '[AttributeUsageAttribute(384)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Field | AttributeTargets.Property)]' in the implementation.
Expand All @@ -40,4 +49,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: 41
Total Issues: 50
4 changes: 2 additions & 2 deletions src/AutoMapper/Configuration/MapperConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ TypeMap FindClosedGenericMap(TypePair typePair)
FindTypeMapFor(genericTypePair.SourceType, typePair.DestinationType) ??
FindTypeMapFor(typePair.SourceType, genericTypePair.DestinationType) ??
FindTypeMapFor(genericTypePair);
ITypeMapConfiguration genericMapConfig;
TypeMapConfiguration genericMapConfig;
ProfileMap profile;
TypeMap cachedMap;
TypePair closedTypes;
Expand Down Expand Up @@ -461,7 +461,7 @@ void IGlobalConfiguration.AssertConfigurationIsValid(string profileName)
}
void IGlobalConfiguration.AssertConfigurationIsValid<TProfile>() => this.Internal().AssertConfigurationIsValid(typeof(TProfile).FullName);
void IGlobalConfiguration.Seal(TypeMap typeMap) => typeMap.Seal(this, _typeMapsPath);
void IGlobalConfiguration.RegisterAsMap(ITypeMapConfiguration typeMapConfiguration) =>
void IGlobalConfiguration.RegisterAsMap(TypeMapConfiguration typeMapConfiguration) =>
_resolvedMaps[typeMapConfiguration.Types] = GetIncludedTypeMap(new(typeMapConfiguration.SourceType, typeMapConfiguration.DestinationTypeOverride));
}
}
70 changes: 9 additions & 61 deletions src/AutoMapper/Configuration/MappingExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@
using System.Linq.Expressions;
using System.Reflection;
using AutoMapper.Internal;

namespace AutoMapper.Configuration
{
using Execution;
public class MappingExpression : MappingExpressionBase<object, object, IMappingExpression>, IMappingExpression
{
public MappingExpression(TypePair types, MemberList memberList) : base(memberList, types)
{
}

public MappingExpression(TypePair types, MemberList memberList) : base(memberList, types){}
public string[] IncludedMembersNames { get; internal set; } = Array.Empty<string>();

public IMappingExpression ReverseMap()
{
var reversedTypes = new TypePair(DestinationType, SourceType);
Expand All @@ -30,7 +25,6 @@ public IMappingExpression ReverseMap()
}
return reverseMap;
}

public IMappingExpression IncludeMembers(params string[] memberNames)
{
IncludedMembersNames = memberNames;
Expand All @@ -41,7 +35,6 @@ public IMappingExpression IncludeMembers(params string[] memberNames)
TypeMapActions.Add(tm => tm.IncludedMembersNames = memberNames);
return this;
}

public void ForAllMembers(Action<IMemberConfigurationExpression> memberOptions)
{
TypeMapActions.Add(typeMap =>
Expand All @@ -52,32 +45,23 @@ public void ForAllMembers(Action<IMemberConfigurationExpression> memberOptions)
}
});
}

public IMappingExpression ForMember(string name, Action<IMemberConfigurationExpression> memberOptions)
{
var member = DestinationType.GetFieldOrProperty(name);
ForMember(member, memberOptions);
return this;
}

protected override void IgnoreDestinationMember(MemberInfo property, bool ignorePaths = true) => ForMember(property, o=>o.Ignore());

internal MemberConfigurationExpression ForMember(MemberInfo destinationProperty, Action<IMemberConfigurationExpression> memberOptions)
{
var expression = new MemberConfigurationExpression(destinationProperty, SourceType);

MemberConfigurations.Add(expression);

memberOptions(expression);

return expression;
}

public class MemberConfigurationExpression : MemberConfigurationExpression<object, object, object>, IMemberConfigurationExpression
{
public MemberConfigurationExpression(MemberInfo destinationMember, Type sourceType) : base(destinationMember, sourceType)
{
}
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<,,,>)))
Expand All @@ -103,15 +87,10 @@ private void ConvertUsingCore(Type valueConverterType, string sourceMemberName =
});
}
}

public class MappingExpression<TSource, TDestination> :
MappingExpressionBase<TSource, TDestination, IMappingExpression<TSource, TDestination>>,
public class MappingExpression<TSource, TDestination> : MappingExpressionBase<TSource, TDestination, IMappingExpression<TSource, TDestination>>,
IMappingExpression<TSource, TDestination>, IProjectionExpression<TSource, TDestination>
{
public MappingExpression(MemberList memberList, bool projection = false) : base(memberList)
{
Projection = projection;
}
public MappingExpression(MemberList memberList, bool projection = false) : base(memberList) => Projection = projection;
public MappingExpression(MemberList memberList, Type sourceType, Type destinationType) : base(memberList, sourceType, destinationType) { }
public IMappingExpression<TSource, TDestination> ForPath<TMember>(Expression<Func<TDestination, TMember>> destinationMember,
Action<IPathConfigurationExpression<TSource, TDestination, TMember>> memberOptions)
Expand All @@ -131,15 +110,12 @@ public IMappingExpression<TSource, TDestination> ForPath<TMember>(Expression<Fun
memberOptions(expression);
return this;
}

public IMappingExpression<TSource, TDestination> ForMember<TMember>(Expression<Func<TDestination, TMember>> destinationMember, Action<IMemberConfigurationExpression<TSource, TDestination, TMember>> memberOptions)
{
var memberInfo = ReflectionHelper.FindProperty(destinationMember);
return ForDestinationMember(memberInfo, memberOptions);
}

private void IncludeMembersCore(LambdaExpression[] memberExpressions) => TypeMapActions.Add(tm => tm.IncludedMembers = memberExpressions);

public IMappingExpression<TSource, TDestination> IncludeMembers(params Expression<Func<TSource, object>>[] memberExpressions)
{
var memberExpressionsWithoutCastToObject = Array.ConvertAll(
Expand All @@ -149,17 +125,14 @@ public IMappingExpression<TSource, TDestination> IncludeMembers(params Expressio
var bodyIsCastToObject = e.Body.NodeType == ExpressionType.Convert && e.Body.Type == typeof(object);
return bodyIsCastToObject ? Expression.Lambda(((UnaryExpression)e.Body).Operand, e.Parameters) : e;
});

IncludeMembersCore(memberExpressionsWithoutCastToObject);
return this;
}

public IMappingExpression<TSource, TDestination> ForMember(string name, Action<IMemberConfigurationExpression<TSource, TDestination, object>> memberOptions)
{
var member = DestinationType.GetFieldOrProperty(name);
return ForDestinationMember(member, memberOptions);
}

public void ForAllMembers(Action<IMemberConfigurationExpression<TSource, TDestination, object>> memberOptions)
{
TypeMapActions.Add(typeMap =>
Expand All @@ -170,68 +143,43 @@ public void ForAllMembers(Action<IMemberConfigurationExpression<TSource, TDestin
}
});
}

public IMappingExpression<TSource, TDestination> Include<TOtherSource, TOtherDestination>()
where TOtherSource : TSource
where TOtherDestination : TDestination
public IMappingExpression<TSource, TDestination> Include<TOtherSource, TOtherDestination>() where TOtherSource : TSource where TOtherDestination : TDestination
{
IncludeCore(typeof(TOtherSource), typeof(TOtherDestination));

return this;
}

public IMappingExpression<TSource, TDestination> IncludeBase<TSourceBase, TDestinationBase>()
=> IncludeBase(typeof(TSourceBase), typeof(TDestinationBase));

public IMappingExpression<TSource, TDestination> IncludeBase<TSourceBase, TDestinationBase>() => IncludeBase(typeof(TSourceBase), typeof(TDestinationBase));
public IMappingExpression<TSource, TDestination> ForSourceMember(Expression<Func<TSource, object>> sourceMember, Action<ISourceMemberConfigurationExpression> memberOptions)
{
var memberInfo = ReflectionHelper.FindProperty(sourceMember);

var srcConfig = new SourceMappingExpression(memberInfo);

memberOptions(srcConfig);

SourceMemberConfigurations.Add(srcConfig);

return this;
}

public void As<T>() where T : TDestination => As(typeof(T));

public IMappingExpression<TSource, TDestination> AddTransform<TValue>(Expression<Func<TValue, TValue>> transformer)
{
var config = new ValueTransformerConfiguration(typeof(TValue), transformer);

ValueTransformers.Add(config);

return this;
}

public IMappingExpression<TDestination, TSource> ReverseMap()
{
var reverseMap = new MappingExpression<TDestination, TSource>(MemberList.None, DestinationType, SourceType)
{
IsReverseMap = true
};
var reverseMap = new MappingExpression<TDestination, TSource>(MemberList.None, DestinationType, SourceType){ IsReverseMap = true };
ReverseMapCore(reverseMap);
reverseMap.IncludeMembersCore(MapToSourceMembers().Select(m => m.GetDestinationExpression()).ToArray());
return reverseMap;
}

private IMappingExpression<TSource, TDestination> ForDestinationMember<TMember>(MemberInfo destinationProperty, Action<MemberConfigurationExpression<TSource, TDestination, TMember>> memberOptions)
{
var expression = new MemberConfigurationExpression<TSource, TDestination, TMember>(destinationProperty, SourceType);

MemberConfigurations.Add(expression);

memberOptions(expression);

return this;
}

protected override void IgnoreDestinationMember(MemberInfo property, bool ignorePaths = true)
=> ForDestinationMember<object>(property, options => options.Ignore(ignorePaths));

protected override void IgnoreDestinationMember(MemberInfo property, bool ignorePaths = true) =>
ForDestinationMember<object>(property, options => options.Ignore(ignorePaths));
IProjectionExpression<TSource, TDestination> IProjectionExpression<TSource, TDestination>.ForMember<TMember>(Expression<Func<TDestination, TMember>> destinationMember,
Action<IProjectionMemberConfiguration<TSource, TDestination, TMember>> memberOptions) =>
(IProjectionExpression<TSource, TDestination>)ForMember(destinationMember, memberOptions);
Expand Down
Loading