Serializing and Deserializing Expression Trees to and from json #5555
Replies: 3 comments 7 replies
-
This sounds like more of an ask of the runtime repository, which handles the APIs and base class libraries and manages the classes used for expression trees. However, I would think that with any JSON library that supports custom serialization/deserialization that functionality like this could be achieved entirely without language or runtime support, e.g. by implementing a |
Beta Was this translation helpful? Give feedback.
-
If efficiency is important, how about writing ordinary c# code, compiling it, and storing the DLL in the database as a binary blob? Then you can load the DLL and run it |
Beta Was this translation helpful? Give feedback.
-
The LINQ expression trees are not serialization friendly out of the box, regardless of what JSON library you use. You would have to write a custom serializer/deserializer (or perhaps somebody else created a LINQ expression tree serializer on Nuget?) |
Beta Was this translation helpful? Give feedback.
-
This is my first post, so please excuse any mistakes I make.
Can we have the ability to serialize and deserialize expression trees.
Scenario:
I have a piece of functionality where the logic that does the calculation or validation can change frequently or depending on our customer.
I would like to create an expression lambda (a block expression) which I can serialize and save in the database and then the code can read and deserialize the expression into an expression tree, which I can then run on production.
What we've tried:
To achieve something similar I've tried CSharpScript, however, it was reported that the introduction of CSharpScript caused more memory to be used, not to mention more time consumed to compile and run the code.
I believe expression trees should be faster than CSharpScript and also they should consume less memory to cache a compiled expression lambda in memory so that it can be reused more easily.
Please let me know if this seems reasonable.
Looking forward to your expert comments and feedback.
Beta Was this translation helpful? Give feedback.
All reactions