dynamicexpresso / DynamicExpresso

C# expressions interpreter
http://dynamic-expresso.azurewebsites.net/
MIT License
2.02k stars 379 forks source link

feat: .net 8 and github issue 311 #313

Closed davideicardi closed 3 months ago

davideicardi commented 3 months ago

Configured .NET runtime 8.0, removed support for .NET 3.1.

Close #311: Add a test to demostrate that it is not a bug. Substring method in .NET (https://learn.microsoft.com/en-us/dotnet/api/system.string.substring?view=net-8.0#system-string-substring(system-int32-system-int32)) it is not defined for Decimal type, so if we force all types to be decimal it will not work unless you perform a cast to int.

var interpreter2 = new Interpreter().SetDefaultNumberType(DefaultNumberType.Decimal);
interpreter2.SetVariable("a", a);
// expected to throw because Substring is not defined for decimal
Assert.Throws<NoApplicableMethodException>(() => interpreter2.Eval("a.Substring(0, 2)"));
// It works if we cast to int
Assert.AreEqual("AA", interpreter2.Eval("a.Substring((int)0, (int)2)"));