473,395 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 8893

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Charlie | last post by:
I have the first part of the project done but I'm having difficulty deciding how to add an evaluate function to this program. The program asks the user to enter a function in infix notation and...
1
by: Christoph Putz | last post by:
Hi! How can i do somewhat like saxon:evaluate in my xslt transformation? I tried to write an extension object, but in my case i need some context information (the value of an xslt-variable) to...
1
by: David Laub | last post by:
I have no problems running the following dynamic XPath evaluator form MSXSL: <msxsl:script implements-prefix="dyn" language="jscript"> evaluate(context, expression) { return...
3
by: Jason luo | last post by:
Hi all, In c99-standard page 52,there is a sentence about void,as below: If an expression of any other type is evaluated as a void expression, its value or designator is discarded. I don't...
4
by: Zeng | last post by:
Hello, I just wonder if there is a way to programmatically evaluate expression strings such as ( ( 3 + 5 ) / 2 ) > 4 --> this should return 0 or false ( ( 3 + 6 ) / 3 ) > ( ( 5 + 3 ) / 4 ) ...
13
by: Zeng | last post by:
Hello, Please help!!! I've been stuck on this issue for months. I just wonder if there is a way to programmatically evaluate expression strings such as ( ( 3 + 5 ) / 2 ) > 4 --> this...
8
by: No Such Luck | last post by:
Is there anyway to literally evaluate the contents of a string in an if statement? For example: int i = 0; char * str = "i == 0"; if(str) /* I know this doesn't do what I want */ {
0
by: SubasreeG | last post by:
Hi, I have a situation where expression to evaluate comes from the user. I have to execute the expression and based upon the result i have to perform certain operation. The problem is that the...
2
by: Björn Langhof | last post by:
Hello. I want to evaluate a XPath-Expression only on a subtree of the whole xml-document. 1. I select a node of the XML-document 2. Then a want to select specific nodes below the node chosen...
1
by: aitia | last post by:
this the code. i used ECLIPSE to run this.. it has some codes smells that i can't seem to figure out.. can any one help? import java.io.*; import java.util.*; public class Postfix { private...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.