LINQ Expressions: the Nreco Framework give compile error

196 Views Asked by At

It is the first time I use nuget and I am trying to compile a dynamic lambda parser example from NRecoFramework as shown below:

    var lambdaParser = new NReco.LambdaParser();
    var varContext = new Dictionary<string, object>();
    varContext["one"] = 1M;
    varContext["two"] = "2";

    Console.WriteLine(lambdaParser.Eval("two>one && 0<one ? (1+8)/3+1*two : 0", varContext)); // --> 5`

but when I try to compile, the LamdaParser() method is not recognized.

I have already imported the nuget and nreco frameworks to VisualStudio2017 but it still doesn't compile.

Print of My Code

SOLVED

My bad, the problem was that I had imported both the Nreco Package and Nreco.LambdaParser Package, as the LamdaParser() method exits at both packages I was unable to compile. After removing Nreco.LamdaParser package the problem was solved.

1

There are 1 best solutions below

2
On BEST ANSWER

It appears that the example on the framework site is either outdated or simply wrong.
Their API documentation is up to date.

The LambdaParser is in the NReco.Linq namespace. You'll need to change your code to:

var lambdaParser = new NReco.Linq.LambdaParser();
var varContext = new Dictionary<string, object>();
varContext["one"] = 1M;
varContext["two"] = "2";

Console.WriteLine(lambdaParser.Eval("two>one && 0<one ? (1+8)/3+1*two : 0", varContext)); // --> 5`

Or, since you have a using NReco.Linq; declaration in your file, you can also write:

var lambdaParser = new LambdaParser();
var varContext = new Dictionary<string, object>();
varContext["one"] = 1M;
varContext["two"] = "2";

Console.WriteLine(lambdaParser.Eval("two>one && 0<one ? (1+8)/3+1*two : 0", varContext)); // --> 5`