469,282 Members | 1,704 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

Evaluate expression at run-time?

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?
Jul 21 '05 #1
2 8706

"John Spiegel" <js******@NOSPAMc-comld.com> wrote in message
news:%2*****************@TK2MSFTNGP12.phx.gbl...
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

Jul 21 '05 #2
Thanks, Fredrik!

"Fredrik Wahlgren" <fr****************@mailbox.swipnet.se> wrote in message
news:uf**************@TK2MSFTNGP12.phx.gbl...

"John Spiegel" <js******@NOSPAMc-comld.com> wrote in message
news:%2*****************@TK2MSFTNGP12.phx.gbl...
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

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Charlie | last post: by
1 post views Thread by Christoph Putz | last post: by
8 posts views Thread by No Such Luck | last post: by
reply views Thread by SubasreeG | last post: by
2 posts views Thread by Björn Langhof | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.