473,397 Members | 2,028 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,397 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 8894

"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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.