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

Please explain more about how it works #54

Closed daveyostcom closed 5 years ago

daveyostcom commented 5 years ago

Please greatly expand the Documentation. Many things are mysterious. Documentation about how things work would really help.

See my examples.

JonathanMagnan commented 5 years ago

Hello @daveyostcom ,

We currently work hard on our documentation as we know that's currently a big issue for everyone with all our libraries.

We are currently making some good progress with Entity Framework Extensions, we should move after on Dapper Plus and then C# Eval Expression.


That being said, I believe you currently use the library in a very wrong way which make it harder to understand it.

Our library doesn't know about your assembly or type you want to include. So you need to register them: https://eval-expression.net/register-unregister

Why do I have to put names for variables in my code into a dictionary, whereas things from certain libraries are just there. Btw, which libraries are included?

I believe your code currently add way too much stuff in the dictionary. You can do the same without a dictionary.

Fiddle: https://dotnetfiddle.net/erDA0k

How do I use the name of one of my classes in a script? For example, I can't say var foo = new Holder(); I had to work around this by making a function that calls new Holder(), making a delegate that points to it, adding the delegate to the dictionary, and calling the delegate in the script.

You should not do it this way and register your type instead

Fiddle: https://dotnetfiddle.net/Q62Mom

I had to experiment to see how to allow the script code to call a method. And it's not obvious that you can declare a delegate and put that in the dictionary.

I guess with previous example, you now understand that you should not do it this way ;)

Let me know if you have more question.

Best Regards,

Jonathan

daveyostcom commented 5 years ago

Fantastic! Thanks!

daveyostcom commented 5 years ago

What are the space/performance tradeoffs of using register instead of a dictionary, in cases where the dictionary can work?

One advantage of the dictionary approach would be allowing the script to access only certain symbols, yes?

JonathanMagnan commented 5 years ago

I believe the only tradeoff is readability.

Performance, memory space or similar tradeoffs are just to small for those cases to make a difference.

You can also access to only specific class by using RegisterType instead of registering an assembly.