0

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.

slugster
  • 49,403
  • 14
  • 95
  • 145
Roger S
  • 15
  • 4

1 Answers1

1

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`
Mor A.
  • 3,805
  • 2
  • 16
  • 19
  • My bad, the problem was that I had imported both the Nreco package and the Nreco.LambdaParser Package, as the LamdaParser methos exits at both I was unable to compile. After removing the Nreco.LamdaParser package the problem was solved. – Roger S Aug 01 '18 at 11:23
  • 1
    @RogerMoschiel as library author I recommend to use "NReco.LambdaParser" nuget package which contains _only_ LambdaParser functionality. Legacy "NReco" nuget package is outdated and not supported any more (and will be unlisted from nuget.org in future). – Vitaliy Fedorchenko Aug 06 '18 at 12:43