zzzprojects / Eval-Expression.NET

C# Eval Expression | Evaluate, Compile, and Execute C# code and expression at runtime.
https://eval-expression.net/
Other
459 stars 86 forks source link

Issues with Array Initialization #85

Closed marcOcram closed 4 years ago

marcOcram commented 4 years ago

Hello,

if an integer array is initialized with an equation it is not parsed as expected.

int[] expectedResult = new int[] { 1 + 1 };
int[] result = Eval.Execute<int[]>("new int[] { 1 + 1 }");
if (result[0] != expectedResult[0]) {
    Console.WriteLine("Result was " + result[0] + " but expected " + expectedResult[0] + "!");  
}

Additionally the following results in an InvalidCastException. This happens only using array initialization.

Eval.Execute<long[]>("new long[] { 1L + 1L }")

These issues do not appear while using List<int>.

A reproduction is available as fiddle.

JonathanMagnan commented 4 years ago

Hello @marcOcram ,

Thank you for reporting,

We will look if we can improve this part.

Best Regards,

Jon

JonathanMagnan commented 4 years ago

Hello @marcOcram ,

The v4.0.21 has been released.

Both issues should now be fixed and working correctly.

Let me know if everything works as expected on your side.

Best Regards,

Jon

marcOcram commented 4 years ago

Hello @JonathanMagnan

it works like a charm. Thanks for the really quick fix.

JonathanMagnan commented 4 years ago

Awesome!

We are glad everything is working out for you!

Don't hesitate to contact us for questions, issues or feedback!

Best regards,

Jon