Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
consider VB closures
  • Loading branch information
lbargaoanu committed Oct 24, 2016
commit 46a245b6b9ba53177871b02bf28dd4b00007ee8c
23 changes: 15 additions & 8 deletions src/AutoMapper/QueryableExtensions/ExpressionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace AutoMapper.QueryableExtensions
{
using System.Runtime.CompilerServices;
using Configuration;
using Execution;

Expand Down Expand Up @@ -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.HasAttribute<CompilerGeneratedAttribute>())
{
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) || !_paramValues.TryGetValue(parameterName.Substring(VBPrefix.Length), out parameterValue))
{
return base.VisitMember(node);
}
}
return Convert(Constant(parameterValue), node.Member.GetMemberType());
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/AutoMapper/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ namespace AutoMapper
#endif

internal static class TypeExtensions
{
{
public static bool HasAttribute<TAttribute>(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;
Expand Down