I am using reflection to create a lambda function. It works with most items I try it with, however on one of the properties it keeps throwing an Ambiguous Match Exception.
The code looks like this. The error happens when it hits Expression.PropertyOrField. The property I am using is of type decimal?
. I think it might have to do with the fact that it is a nullable type, but I'm not sure.
public static LambdaExpression CreateExpression(Type type, string propertyName, ref Type returnType)
{
var param = Expression.Parameter(type, "x");
Expression body = param;
foreach (var member in propertyName.Split('.'))
{
body = Expression.PropertyOrField(body, member);
}
returnType = body.Type;
return Expression.Lambda(body, param);
}
Aucun commentaire:
Enregistrer un commentaire