Reputation: 55
I am working on a Blazor WebAssembly project using .NET 8, and I am utilizing the DynamicExpresso library to evaluate my expressions.
If we use interpreter.SetDefaultNumberType(DefaultNumberType.Decimal) , then we can't access any default library like string related or Math related functions etc.
interpreter = new Interpreter().SetDefaultNumberType(DefaultNumberType.Decimal);
After this if we try to evaluate below string for a loaded variable strVariable , Below expression will not evaluate.
strVariable.Substring(0, 40)
if we create the interpreter with this interpreter = new Interpreter() then above expression will evaluate.
I have tried to add reference for the string and Math lib as below , but it still does not work , it only works if we remove the SetDefaultNumberType option.
interpreter = interpreter.Reference(typeof(System.String));
interpreter = interpreter.Reference(typeof(System.Math));
can someone help on this issue. as we need to set Default Number Type and also have some access to libraries for extension methods etc.
For Example:
using DynamicExpresso;
var interpreter = new Interpreter();
var result = interpreter.Eval("\"abcdefg\".Substring(2)");
Console.WriteLine(result.ToString());
This code is working Perfectly And
using DynamicExpresso;
var interpreter = new Interpreter();
interpreter.SetDefaultNumberType(DefaultNumberType.Decimal);
var result = interpreter.Eval("\"abcdefg\".Substring(2)");
Console.WriteLine(result.ToString());
And this code show Error that substring not found.
I need both string functions and DeafaultNumber=Decimal.
Any guidance or suggestions would be greatly appreciated.
Upvotes: 0
Views: 39