Evaluate expression at run-time?

  • Thread starter Thread starter John Spiegel
  • Start date Start date
J

John Spiegel

Hi all,

Is it possible to have an uncompiled C# expression evaluated at runtime?
I'd like to store an expression within an XML file then evaluate it when the
time comes, something like:

MyExpression = "DateTime.Today.Month % 2) = 0?"Even\":\"Odd\"";

string strResultString = MyExpression.Evaluate();

where MyExpression.Evaluate() represents a method that would evaluate the
text as a command, returning "Odd" (this month) to the strResultString.

Is something like this possible?
 
John Spiegel said:
Hi all,

Is it possible to have an uncompiled C# expression evaluated at runtime?
I'd like to store an expression within an XML file then evaluate it when the
time comes, something like:

MyExpression = "DateTime.Today.Month % 2) = 0?"Even\":\"Odd\"";

string strResultString = MyExpression.Evaluate();

where MyExpression.Evaluate() represents a method that would evaluate the
text as a command, returning "Odd" (this month) to the strResultString.

Is something like this possible?

Yes.
http://codeproject.com/csharp/runtime_eval.asp
http://www.odetocode.com/Code/80.aspx

Best Regards,
Fredrik
 
Back
Top