2

我正在使用动态 Linq 库来解析布尔表达式。在这种方法中:

public static LambdaExpression Parse(SearchQuery query)
{
    string compilableExpression = BuildCompilableExpression(query);

    ParameterExpression parameter = System.Linq.Expressions.Expression.Parameter(typeof(EventListItem));
    return System.Linq.Dynamic.DynamicExpression.ParseLambda(new[] { parameter }, null, compilableExpression);
}

BuildCompilableExpression返回此字符串:

"long.Parse(InstanceID.ToString()) == long.Parse(\"2\")"

哪个是正确的(InstanceID是 中的一个属性EventListItem),但是,调用ParseLambda()失败并出现以下异常:

No property or field 'long' exists in type 'EventListItem'

我试过解析一个包含string.Compare()并且工作得很好的表达式,所以我不明白为什么long.Parse()不起作用。我只是想知道是否有人这样做过。任何帮助表示赞赏。

4

2 回答 2

2

long isn't the name of a type, it is a shortcut provided by C#. Int64 is the technical name, have you tried that? Similarly String is the name of the string type.

Note that string might have worked because while C# is case sensitive, the analyzer may or may not be.

于 2013-05-20T23:59:28.823 回答
2

long.NET 中不存在该类型。long是 C# 关键字并且是 .NET 类型的别名System.Int64。尝试使用Int64.Parse(...).

于 2013-05-20T21:35:53.983 回答