Reputation: 7423
I'm using the Dynamic Linq Library to parse a boolean expression. In this method:
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
returns this string:
"long.Parse(InstanceID.ToString()) == long.Parse(\"2\")"
Which is correct (InstanceID
is a property in the EventListItem
), however, the call to ParseLambda()
failes with this exception:
No property or field 'long' exists in type 'EventListItem'
I've tried parsing an expression that contains string.Compare()
and that works just fine, so I don't understand why long.Parse()
doesn't work. I was just wondering if anyone has ever done this. Any help is appreciated.
Upvotes: 2
Views: 629
Reputation: 19213
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.
Upvotes: 2
Reputation: 12934
The type long
does not exist in .NET. long
is a C# keyword and is an alias for the .NET type System.Int64
. Try using Int64.Parse(...)
.
Upvotes: 2