Consider this code fragment;
int sum = 0;
sum = Expression.Evaluate("1+1");
where the value of sum = 2
I do have an expression that will compute values but i want that expression to be build programatically then evaluate the result. I don’t have any idea what class or namespace that I will dealing with. Anyone can help me.
You could use Expression Trees:
Expression Trees (C# and Visual Basic)
Expression Tree Basics
Note: This problem can be solved using
System.Reflection.Emitand work directly with MSIL, but the resulting code is hard to write and read.After a little browsing, I suggest you checkout Flee on Codeplex: Fast Lightweight Expression Evaluator :