Dynamic Linq cannot parse long.Parse()

c# dynamic-linq

Question

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.

1
2
5/20/2013 8:58:53 PM

Accepted Answer

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.

2
5/20/2013 11:59:28 PM

Popular Answer

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(...).



Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow