|
|
@ -55,10 +55,9 @@ public class DefaultObjectMapper : IObjectMapper, ITransientDependency |
|
|
return specificMapper.Map(source); |
|
|
return specificMapper.Map(source); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var result = TryToMapCollection<TSource, TDestination>(scope, source, default); |
|
|
if (TryToMapCollection<TSource, TDestination>(scope, source, default, out var collectionResult)) |
|
|
if (result != null) |
|
|
|
|
|
{ |
|
|
{ |
|
|
return result; |
|
|
return collectionResult; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -100,10 +99,9 @@ public class DefaultObjectMapper : IObjectMapper, ITransientDependency |
|
|
return specificMapper.Map(source, destination); |
|
|
return specificMapper.Map(source, destination); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var result = TryToMapCollection(scope, source, destination); |
|
|
if (TryToMapCollection(scope, source, destination, out var collectionResult)) |
|
|
if (result != null) |
|
|
|
|
|
{ |
|
|
{ |
|
|
return result; |
|
|
return collectionResult; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -122,11 +120,12 @@ public class DefaultObjectMapper : IObjectMapper, ITransientDependency |
|
|
return AutoMap(source, destination); |
|
|
return AutoMap(source, destination); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected virtual TDestination? TryToMapCollection<TSource, TDestination>(IServiceScope serviceScope, TSource source, TDestination? destination) |
|
|
protected virtual bool TryToMapCollection<TSource, TDestination>(IServiceScope serviceScope, TSource source, TDestination? destination, out TDestination collectionResult) |
|
|
{ |
|
|
{ |
|
|
if (!IsCollectionGenericType<TSource, TDestination>(out var sourceArgumentType, out var destinationArgumentType, out var definitionGenericType)) |
|
|
if (!IsCollectionGenericType<TSource, TDestination>(out var sourceArgumentType, out var destinationArgumentType, out var definitionGenericType)) |
|
|
{ |
|
|
{ |
|
|
return default; |
|
|
collectionResult = default!; |
|
|
|
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var mapperType = typeof(IObjectMapper<,>).MakeGenericType(sourceArgumentType, destinationArgumentType); |
|
|
var mapperType = typeof(IObjectMapper<,>).MakeGenericType(sourceArgumentType, destinationArgumentType); |
|
|
@ -134,7 +133,8 @@ public class DefaultObjectMapper : IObjectMapper, ITransientDependency |
|
|
if (specificMapper == null) |
|
|
if (specificMapper == null) |
|
|
{ |
|
|
{ |
|
|
//skip, no specific mapper
|
|
|
//skip, no specific mapper
|
|
|
return default; |
|
|
collectionResult = default!; |
|
|
|
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var cacheKey = $"{mapperType.FullName}_{(destination == null ? "MapMethodWithSingleParameter" : "MapMethodWithDoubleParameters")}"; |
|
|
var cacheKey = $"{mapperType.FullName}_{(destination == null ? "MapMethodWithSingleParameter" : "MapMethodWithDoubleParameters")}"; |
|
|
@ -209,11 +209,13 @@ public class DefaultObjectMapper : IObjectMapper, ITransientDependency |
|
|
if (destination != null && destination.GetType().IsArray) |
|
|
if (destination != null && destination.GetType().IsArray) |
|
|
{ |
|
|
{ |
|
|
//Return the new collection if destination is an array, We won't change array just same behavior as AutoMapper.
|
|
|
//Return the new collection if destination is an array, We won't change array just same behavior as AutoMapper.
|
|
|
return (TDestination)result; |
|
|
collectionResult = (TDestination)result; |
|
|
|
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Return the destination if destination exists. The parameter reference equals with return object.
|
|
|
//Return the destination if destination exists. The parameter reference equals with return object.
|
|
|
return destination ?? (TDestination)result; |
|
|
collectionResult = destination ?? (TDestination)result; |
|
|
|
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected virtual bool IsCollectionGenericType<TSource, TDestination>(out Type sourceArgumentType, out Type destinationArgumentType, out Type definitionGenericType) |
|
|
protected virtual bool IsCollectionGenericType<TSource, TDestination>(out Type sourceArgumentType, out Type destinationArgumentType, out Type definitionGenericType) |
|
|
|