zzzprojects / Eval-Expression.NET

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

"Not" operator parsing problem #29

Closed rodro75 closed 6 years ago

rodro75 commented 6 years ago

Hi guys,

This isn't a big concern, since there are workarounds, but I thought you might be interested. Given an eval context where I registered this static method:


    public static class MyMethods
    {
        public static bool GiveMeTrue()
        {
            return true;
        }
    }

            var context = new EvalContext {UseCache = false};
            context.RegisterStaticMember(typeof(MyMethods));
            context.RegisterType(typeof(MyMethods));

The following works as expected: var result = context.Execute("GiveMeTrue()"); Assert.IsTrue(result);

But the following throws a compile error: Oops! The type could not be found. var result = context.Execute("!GiveMeTrue()"); Assert.IsFalse(result);

Unless I enclose the method invocation in parens: var result = context.Execute("!(GiveMeTrue())"); Assert.IsFalse(result);

Now, if I write this the error message is differnet, actually more to the point I think: -Missing left expression for binary keyword or operator "==" at position 14 near "== true"- var result = context.Execute("!GiveMeTrue() == true"); Assert.IsFalse(result);

Again, by using extra parens the parser get it right. var result = context.Execute("!(GiveMeTrue()) == true"); Assert.IsFalse(result);

-Rodrigo-

JonathanMagnan commented 6 years ago

Hello @rodro75 ,

Thank you for reporting,

We will for sure look at it.

Best Regards,

Jonathan

JonathanMagnan commented 6 years ago

Hello @rodro75 ,

The v2.4.18 has been released.

The NOT operator should now work correctly with all your cases.

Best Regards,

Jonathan

rodro75 commented 6 years ago

Hi @JonathanMagnan ,

I confirm that it now works as expected.

Thank you very much.

-Rodrigo-