diff --git a/src/AutoMapper/QueryableExtensions/ExpressionBuilder.cs b/src/AutoMapper/QueryableExtensions/ExpressionBuilder.cs index 9ddcae2310..020e243406 100644 --- a/src/AutoMapper/QueryableExtensions/ExpressionBuilder.cs +++ b/src/AutoMapper/QueryableExtensions/ExpressionBuilder.cs @@ -9,6 +9,7 @@ namespace AutoMapper.QueryableExtensions { + using System.Runtime.CompilerServices; using Configuration; using Execution; @@ -264,15 +265,21 @@ public ConstantExpressionReplacementVisitor( protected override Expression VisitMember(MemberExpression node) { - if (!node.Member.DeclaringType.Name.Contains("<>")) - return base.VisitMember(node); - - if (!_paramValues.ContainsKey(node.Member.Name)) + if(!node.Member.DeclaringType.Has()) + { return base.VisitMember(node); - - return Expression.Convert( - Expression.Constant(_paramValues[node.Member.Name]), - node.Member.GetMemberType()); + } + object parameterValue; + var parameterName = node.Member.Name; + if(!_paramValues.TryGetValue(parameterName, out parameterValue)) + { + const string VBPrefix = "$VB$Local_"; + if(!parameterName.StartsWith(VBPrefix, StringComparison.Ordinal) || !_paramValues.TryGetValue(parameterName.Substring(VBPrefix.Length), out parameterValue)) + { + return base.VisitMember(node); + } + } + return Convert(Constant(parameterValue), node.Member.GetMemberType()); } } diff --git a/src/AutoMapper/TypeExtensions.cs b/src/AutoMapper/TypeExtensions.cs index a27ad29eb7..3fb90692cc 100644 --- a/src/AutoMapper/TypeExtensions.cs +++ b/src/AutoMapper/TypeExtensions.cs @@ -10,7 +10,12 @@ namespace AutoMapper #endif internal static class TypeExtensions - { + { + public static bool Has(this Type type) where TAttribute : Attribute + { + return type.GetTypeInfo().IsDefined(typeof(TAttribute), inherit: false); + } + public static Type GetGenericTypeDefinitionIfGeneric(this Type type) { return type.IsGenericType() ? type.GetGenericTypeDefinition() : type;