nreco / lambdaparser

Runtime parser for string expressions (formulas, method calls). Builds dynamic LINQ expression tree and compiles it to lambda delegate.
http://www.nrecosite.com/
MIT License
307 stars 55 forks source link

SL5 MacOs support #26

Open wtlatli opened 4 years ago

wtlatli commented 4 years ago

I am using LambdaParser in a SL5 application, every thing is working correctly on Windows clients, but formulas are not evaluated on MacOs. The application is running with elevated privileges (signed and OOB). Maybe need to reference some extra assemblies ?

VitaliyMF commented 4 years ago

Extra assemblies are 100% not needed.

LambdaParser uses Expression.Compile (from System.Linq.Expression) to get the evaluation result. Maybe on MacOS this API has limitations like on iOS?.. (see https://github.com/nreco/lambdaparser/issues/21).

Unfortunately, I don't have Mac and cannot propose a workaround by myself. Could you try to do the following: modify https://github.com/nreco/lambdaparser/blob/master/src/NReco.LambdaParser/Linq/LambdaParser.cs line 110 and replace "Compile()" with "Compile(true)" (this enables Expression interpretation instead of compilation), then build NReco.LambdaParser.dll and try it on MacOS? If this helps we can add an option for LambdaParser class to use this mode.

If this doesn't help: add own implementation of expression interpreter as an alternative to "Expression.Compile" (this solution 100% will work, but requires some development - your contribution is welcome).

wtlatli commented 4 years ago

Thank you for your response.

I've tryed to implement the proposed workaroud but faced 2 problems: 1- Version 1.0.11 doesnt support PCL natively => had to renenable desired target platform. 2- Compile(bool preferInterpretation) isn't supported for PCL, and I think that Linq's LambdaExpression.Compile() in PCL is already using the interpreter:

public Delegate Compile(bool preferInterpretation) { #if FEATURE_COMPILE #if FEATURE_INTERPRET if (preferInterpretation) { return new Interpreter.LightCompiler().CompileTop(this).CreateDelegate(); } #endif return Compiler.LambdaCompiler.Compile(this); #else return new Interpreter.LightCompiler().CompileTop(this).CreateDelegate(); #endif }

Implementing own Expression.Compile seems to be quite complex and require a huge development effort that I'm not able to do.

VitaliyMF commented 4 years ago

PCL targets are legacy. They are not supported any more by an official build on nuget.org.

Regarding

Implementing own Expression.Compile seems to be quite complex and require a huge development effort that I'm not able to do.

adding own 'interpretation' mode is not a very complex, in fact. Number of operators that are possible in LambdaParser expressions is known and rather limited; to make method/property calls existing helpers may be used. However, interpretation is a much slower than a call of compiled delegate (this may be important if you need to evaluate an expression a lot of times quickly).