Skip to content

Commit 67c6900

Browse files
author
Michael Croes
committed
ExpressionMapper.VisitAllParametersExpression: Only use generic type argument if destSubTypes extends IEnumerable<>
1 parent 553c9f1 commit 67c6900

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/AutoMapper.Extensions.ExpressionMapping/ExpressionMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ private Expression VisitAllParametersExpression<T>(Expression<T> expression)
173173
from t in expression.Parameters
174174
let sourceParamType = t.Type
175175
from destParamType in _destSubTypes.Where(dt => dt != sourceParamType)
176-
let a = destParamType.IsGenericType() ? destParamType.GetTypeInfo().GenericTypeArguments[0] : destParamType
176+
let a = destParamType.IsEnumerableType(out var itemType) ? itemType : destParamType
177177
let typeMap = _configurationProvider.ResolveTypeMap(a, sourceParamType)
178178
where typeMap != null
179179
let oldParam = t

src/AutoMapper.Extensions.ExpressionMapping/TypeExtensions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,5 +171,14 @@ public static bool IsQueryableType(this Type type)
171171

172172
public static Type GetGenericElementType(this Type type)
173173
=> type.HasElementType ? type.GetElementType() : type.GetTypeInfo().GenericTypeArguments[0];
174+
175+
public static bool IsEnumerableType(this Type type, out Type itemType)
176+
{
177+
itemType = type.GetInterfaces()
178+
.FirstOrDefault(t => t.GetGenericTypeDefinitionIfGeneric() == typeof(IEnumerable<>))
179+
?.GetGenericArguments()[0];
180+
181+
return itemType != null;
182+
}
174183
}
175184
}

0 commit comments

Comments
 (0)