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

eval error #58

Closed daveyostcom closed 5 years ago

daveyostcom commented 5 years ago

I intended this example to be equivalent to an example in a previous report, but it doesn't work, and I don't understand the error message:

Run-time exception (line 23): Oops! No applicable member has been found for the expression. The error occurred for expression "addInput" at position 7 near "addInput(2);
      addInp".
JonathanMagnan commented 5 years ago

There is no applicable member with the name "addInput",

A member is a property, method, constructors, fields, etc.

In this Fiddle, I don't find anything either with the name "addInput".

Let me know if that explains better the error message.

daveyostcom commented 5 years ago

I fiddled with the fiddle to add lines that were strangely missing.

JonathanMagnan commented 5 years ago

Oh now it makes sense ;) We will look at it.

JonathanMagnan commented 5 years ago

Hello @daveyostcom ,

It's possible to register static member but that doesn't work with non-static member. An instance must exist and it's impossible for our library which class instance it should use.

One way to make it possible is by providing the instance to the execute method

var result = Eval.Execute(text, this);
daveyostcom commented 5 years ago

I'm fine with that. Thanks. Is it faster to call Execute rather than Compile followed by calling the compiled code? If so, how much.

daveyostcom commented 5 years ago

I updated the test case, but now I wonder why it produces no output.

JonathanMagnan commented 5 years ago

Is it faster to call Execute rather than Compile followed by calling the compiled code

Exactly the same performance. The Execute always call the compile and then execute the returned delegate.

The compile method will be faster when you need to execute the same method multiple time. For example in a loop. The execute method is still fast but needs to build a key and check in a cache if the compiled version exists and that makes it slower than directly using the compiled delegate.

JonathanMagnan commented 5 years ago

I updated the test case, but now I wonder why it produces no output.

You don't have any Console.WriteLine but you might use a different fiddle. Work fine on my side

daveyostcom commented 5 years ago

Fixed. Thanks!

JonathanMagnan commented 5 years ago

Great :)

Let me know if we can close this issue.