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 18, 2022
commit e7ba023083eda38cd4530f3682a7baec093aeced
19 changes: 6 additions & 13 deletions src/AutoMapper/Configuration/MapperConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ public class MapperConfiguration : IGlobalConfiguration
private readonly LockingConcurrentDictionary<MapRequest, Delegate> _executionPlans;
private readonly ConfigurationValidator _validator;
private readonly Features<IRuntimeFeature> _features = new();
private readonly int _recursiveQueriesMaxDepth;
private readonly int _maxExecutionPlanDepth;
private readonly bool _enableNullPropagationForQueryMapping;
private readonly Func<Type, object> _serviceCtor;
private readonly bool _sealed;
private readonly bool _hasOpenMaps;
private readonly HashSet<TypeMap> _typeMapsPath = new();
Expand All @@ -71,11 +67,7 @@ public MapperConfiguration(MapperConfigurationExpression configurationExpression
_mappers = configuration.Mappers.ToArray();
_executionPlans = new(CompileExecutionPlan);
_validator = new(configuration);
_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;
int openTypeMapsCount = Configuration.OpenTypeMapsCount;
Expand Down Expand Up @@ -233,15 +225,16 @@ LambdaExpression GenerateObjectMapperExpression(in MapRequest mapRequest, IObjec
return Lambda(fullExpression, source, destination, ContextParameter);
}
}
ProjectionBuilder CreateProjectionBuilder() => new(this, _validator.Expression.ProjectionMappers.ToArray());
IGlobalConfigurationExpression ConfigurationExpression => _validator.Expression;
ProjectionBuilder CreateProjectionBuilder() => new(this, ConfigurationExpression.ProjectionMappers.ToArray());
IProjectionBuilder IGlobalConfiguration.ProjectionBuilder => _projectionBuilder.Value;
Func<Type, object> IGlobalConfiguration.ServiceCtor => _serviceCtor;
bool IGlobalConfiguration.EnableNullPropagationForQueryMapping => _enableNullPropagationForQueryMapping;
int IGlobalConfiguration.MaxExecutionPlanDepth => _maxExecutionPlanDepth;
Func<Type, object> IGlobalConfiguration.ServiceCtor => ConfigurationExpression.ServiceCtor;
bool IGlobalConfiguration.EnableNullPropagationForQueryMapping => ConfigurationExpression.EnableNullPropagationForQueryMapping.GetValueOrDefault();
int IGlobalConfiguration.MaxExecutionPlanDepth => ConfigurationExpression.MaxExecutionPlanDepth + 1;
private ProfileMap Configuration { get; }
ProfileMap[] IGlobalConfiguration.Profiles => Profiles;
internal ProfileMap[] Profiles { get; }
int IGlobalConfiguration.RecursiveQueriesMaxDepth => _recursiveQueriesMaxDepth;
int IGlobalConfiguration.RecursiveQueriesMaxDepth => ConfigurationExpression.RecursiveQueriesMaxDepth;
Features<IRuntimeFeature> IGlobalConfiguration.Features => _features;
List<MemberInfo> IGlobalConfiguration.SourceMembers => _sourceMembers;
List<ParameterExpression> IGlobalConfiguration.Variables => _variables;
Expand Down
2 changes: 1 addition & 1 deletion src/AutoMapper/Configuration/MappingExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public IMappingExpression<TSource, TDestination> IncludeMembers(params Expressio
e =>
{
var bodyIsCastToObject = e.Body.NodeType == ExpressionType.Convert && e.Body.Type == typeof(object);
return bodyIsCastToObject ? Expression.Lambda(((UnaryExpression)e.Body).Operand, e.Parameters) : e;
return bodyIsCastToObject ? Lambda(((UnaryExpression)e.Body).Operand, e.Parameters) : e;
});
IncludeMembersCore(memberExpressionsWithoutCastToObject);
return this;
Expand Down
2 changes: 1 addition & 1 deletion src/AutoMapper/Execution/ExpressionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,5 +449,5 @@ public class ParameterReplaceVisitor : ReplaceVisitorBase
public class ConvertParameterReplaceVisitor : ParameterReplaceVisitor
{
public override Expression Replace(Expression target, Expression oldNode, Expression newNode) =>
base.Replace(target, oldNode, ExpressionBuilder.ToType(newNode, oldNode.Type));
base.Replace(target, oldNode, ToType(newNode, oldNode.Type));
}
4 changes: 2 additions & 2 deletions src/AutoMapper/Internal/TypeDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ class GenericMethod : MemberInfo
{
readonly MethodInfo _genericMethod;
readonly Type _genericInterface;
MethodInfo _closedMethod = ExpressionBuilder.DecTypeDepthInfo;
MethodInfo _closedMethod = DecTypeDepthInfo;
public GenericMethod(MethodInfo genericMethod, Type genericInterface)
{
_genericMethod = genericMethod;
_genericInterface = genericInterface;
}
public MethodInfo Close()
{
if (_closedMethod == ExpressionBuilder.DecTypeDepthInfo)
if (_closedMethod == DecTypeDepthInfo)
{
// Use method.MakeGenericMethod(genericArguments) wrapped in a try/catch(ArgumentException)
// in order to catch exceptions resulting from the generic arguments not being compatible
Expand Down
2 changes: 1 addition & 1 deletion src/AutoMapper/Mappers/ConstructorMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ private static ConstructorInfo GetConstructor(Type sourceType, Type destinationT
public Expression MapExpression(IGlobalConfiguration configuration, ProfileMap profileMap, MemberMap memberMap, Expression sourceExpression, Expression destExpression)
{
var constructor = GetConstructor(sourceExpression.Type, destExpression.Type);
return Expression.New(constructor, ToType(sourceExpression, constructor.FirstParameterType()));
return New(constructor, ToType(sourceExpression, constructor.FirstParameterType()));
}
}
2 changes: 1 addition & 1 deletion src/AutoMapper/Mappers/ConversionOperatorMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ private MethodInfo GetConversionOperator(Type sourceType, Type destinationType)
public Expression MapExpression(IGlobalConfiguration configuration, ProfileMap profileMap, MemberMap memberMap, Expression sourceExpression, Expression destExpression)
{
var conversionOperator = GetConversionOperator(sourceExpression.Type, destExpression.Type);
return Expression.Call(conversionOperator, ToType(sourceExpression, conversionOperator.FirstParameterType()));
return Call(conversionOperator, ToType(sourceExpression, conversionOperator.FirstParameterType()));
}
}
2 changes: 1 addition & 1 deletion src/AutoMapper/Mappers/KeyValueMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public Expression MapExpression(IGlobalConfiguration configuration, ProfileMap p
var values = new TypePair(sourceArguments[1], destinationArguments[1]);
var mapKeys = configuration.MapExpression(profileMap, keys, ExpressionBuilder.Property(sourceExpression, "Key"));
var mapValues = configuration.MapExpression(profileMap, values, ExpressionBuilder.Property(sourceExpression, "Value"));
return Expression.New(destinationType.GetConstructor(destinationArguments), mapKeys, mapValues);
return New(destinationType.GetConstructor(destinationArguments), mapKeys, mapValues);
}
}
2 changes: 1 addition & 1 deletion src/AutoMapper/Mappers/ParseStringMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ public class ParseStringMapper : IObjectMapper
public bool IsMatch(TypePair context) => context.SourceType == typeof(string) && HasParse(context.DestinationType);
static bool HasParse(Type type) => type == typeof(Guid) || type == typeof(TimeSpan) || type == typeof(DateTimeOffset);
public Expression MapExpression(IGlobalConfiguration configuration, ProfileMap profileMap, MemberMap memberMap, Expression sourceExpression, Expression destExpression) =>
Expression.Call(destExpression.Type.GetMethod("Parse", new[] { typeof(string) }), sourceExpression);
Call(destExpression.Type.GetMethod("Parse", new[] { typeof(string) }), sourceExpression);
}
2 changes: 1 addition & 1 deletion src/AutoMapper/Mappers/ToStringMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class ToStringMapper : IObjectMapper
public Expression MapExpression(IGlobalConfiguration configuration, ProfileMap profileMap, MemberMap memberMap, Expression sourceExpression, Expression destExpression)
{
var sourceType = sourceExpression.Type;
var toStringCall = Call(sourceExpression, ExpressionBuilder.ObjectToString);
var toStringCall = Call(sourceExpression, ObjectToString);
return sourceType.IsEnum ? StringToEnumMapper.CheckEnumMember(sourceExpression, sourceType, toStringCall) : toStringCall;
}
}
2 changes: 1 addition & 1 deletion src/AutoMapper/QueryableExtensions/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static class Extensions
{
static readonly MethodInfo SelectMethod = typeof(Queryable).StaticGenericMethod("Select", parametersCount: 2);
static IQueryable Select(IQueryable source, LambdaExpression lambda) => source.Provider.CreateQuery(
Expression.Call(SelectMethod.MakeGenericMethod(source.ElementType, lambda.ReturnType), source.Expression, Expression.Quote(lambda)));
Call(SelectMethod.MakeGenericMethod(source.ElementType, lambda.ReturnType), source.Expression, Quote(lambda)));
/// <summary>
/// Extension method to project from a queryable using the provided mapping engine
/// </summary>
Expand Down
12 changes: 6 additions & 6 deletions src/AutoMapper/QueryableExtensions/NullsafeQueryRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@ static Expression BeSafe(Expression target, Expression expression, Func<Expressi
if (fallback != null)
{
// coalesce instead, a bit intrusive but fast...
return update(Expression.Coalesce(target, fallback));
return update(Coalesce(target, fallback));
}

// target can be null, which is why we are actually here...
var targetFallback = Expression.Constant(null, target.Type);
var targetFallback = Constant(null, target.Type);

// expression can be default or null, which is basically the same...
var expressionFallback = !IsNullableOrReferenceType(expression.Type)
? (Expression)Expression.Default(expression.Type) : Expression.Constant(null, expression.Type);
? (Expression)Default(expression.Type) : Constant(null, expression.Type);

return Expression.Condition(Expression.Equal(target, targetFallback), expressionFallback, expression);
return Condition(Equal(target, targetFallback), expressionFallback, expression);
}

static bool IsSafe(Expression expression)
Expand All @@ -129,7 +129,7 @@ static Expression Fallback(Type type)
// default value for arrays
if (type.IsArray)
{
return Expression.NewArrayInit(type.GetElementType());
return NewArrayInit(type.GetElementType());
}

return null;
Expand All @@ -142,7 +142,7 @@ static Expression CollectionFallback(Type definition, Type type)
// try if an instance of this collection would suffice
if (type.GetTypeInfo().IsAssignableFrom(collection.GetTypeInfo()))
{
return Expression.Convert(Expression.New(collection), type);
return Convert(New(collection), type);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
namespace AutoMapper.QueryableExtensions.Impl;

[EditorBrowsable(EditorBrowsableState.Never)]
public class AssignableProjectionMapper : IProjectionMapper
{
public bool IsMatch(TypePair context) => context.DestinationType.IsAssignableFrom(context.SourceType);
public Expression Project(IGlobalConfiguration configuration, in ProjectionRequest request, Expression resolvedSource, LetPropertyMaps letPropertyMaps)
=> ExpressionBuilder.ToType(resolvedSource, request.DestinationType);
=> ToType(resolvedSource, request.DestinationType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ public class StringProjectionMapper : IProjectionMapper
{
public bool IsMatch(TypePair context) => context.DestinationType == typeof(string);
public Expression Project(IGlobalConfiguration configuration, in ProjectionRequest request, Expression resolvedSource, LetPropertyMaps letPropertyMaps)
=> Expression.Call(resolvedSource, ExpressionBuilder.ObjectToString);
=> Call(resolvedSource, ObjectToString);
}