473,408 Members | 2,813 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,408 software developers and data experts.

Is it possible to build a generic runtime C# expression evaluation engine?

I'm trying to build a generic runtime C# expression evaluation engine to
allow the user to evaluate any C# code blocks at runtime within the
application's context. For example,

obj4.p4 = obj1.m1() + obj2.m2(p1, p2) - Class3.m3()

or

if (obj1.p1 > obj2.m2())
{
obj3.do()
}

where obj1, obj2 obj4 and Class3 are defined/instantiated in the application
domain. With the generic expression evaluation engine, the user can evaluate
any expressions allowed by the C# syntax and the methods and properties
supported by the defined classes in the application.

With C# Reflection capability, I can evaluate each operand, such as
obj1.m1(), obj2.m2(p1, p2), but I don't know how to evaluate expressions
with operators, such as +, -, *,etc which operates on two operands. I tried
to use Reflection.Emit, but I have to know the expression first to emit the
IL code, which is not possible because the user can write the expressions in
any forms.

C# debugger Watch window has the capability to allow users to input and
evaluate any supported expressions at runtime (at the breakpoints). I like
to have the similar capability but it is built into the application.

Thanks in advance for your help.
Nov 16 '05 #1
2 4262
There is a class Compiler in the Runtime that is able to compile c# code
into memory.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
"Jeffrey Ganping Chen" <je**********@enfocom.com> schrieb im Newsbeitrag
news:#e**************@TK2MSFTNGP12.phx.gbl...
I'm trying to build a generic runtime C# expression evaluation engine to
allow the user to evaluate any C# code blocks at runtime within the
application's context. For example,

obj4.p4 = obj1.m1() + obj2.m2(p1, p2) - Class3.m3()

or

if (obj1.p1 > obj2.m2())
{
obj3.do()
}

where obj1, obj2 obj4 and Class3 are defined/instantiated in the application domain. With the generic expression evaluation engine, the user can evaluate any expressions allowed by the C# syntax and the methods and properties
supported by the defined classes in the application.

With C# Reflection capability, I can evaluate each operand, such as
obj1.m1(), obj2.m2(p1, p2), but I don't know how to evaluate expressions
with operators, such as +, -, *,etc which operates on two operands. I tried to use Reflection.Emit, but I have to know the expression first to emit the IL code, which is not possible because the user can write the expressions in any forms.

C# debugger Watch window has the capability to allow users to input and
evaluate any supported expressions at runtime (at the breakpoints). I like
to have the similar capability but it is built into the application.

Thanks in advance for your help.

Nov 16 '05 #2
http://msdn.microsoft.com/msdnmag/is...rApplications/

may be an option, if you don't mind using JScript.NET or VBScript.NET
instead.

Stu
"Jeffrey Ganping Chen" <je**********@enfocom.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I'm trying to build a generic runtime C# expression evaluation engine to
allow the user to evaluate any C# code blocks at runtime within the
application's context. For example,

obj4.p4 = obj1.m1() + obj2.m2(p1, p2) - Class3.m3()

or

if (obj1.p1 > obj2.m2())
{
obj3.do()
}

where obj1, obj2 obj4 and Class3 are defined/instantiated in the application domain. With the generic expression evaluation engine, the user can evaluate any expressions allowed by the C# syntax and the methods and properties
supported by the defined classes in the application.

With C# Reflection capability, I can evaluate each operand, such as
obj1.m1(), obj2.m2(p1, p2), but I don't know how to evaluate expressions
with operators, such as +, -, *,etc which operates on two operands. I tried to use Reflection.Emit, but I have to know the expression first to emit the IL code, which is not possible because the user can write the expressions in any forms.

C# debugger Watch window has the capability to allow users to input and
evaluate any supported expressions at runtime (at the breakpoints). I like
to have the similar capability but it is built into the application.

Thanks in advance for your help.

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Harry | last post by:
Hi there, does anyone know how I can build a regular expression e.g. for the string.search() function on runtime, depending on the content of variables? Should be something like this: var...
13
by: Douglas Buchanan | last post by:
I am using the following code instead of a very lengthly select case statement. (I have a lot of lookup tables in a settings form that are selected from a ListBox. The data adapters are given a...
8
by: Brian Blais | last post by:
Hello, I have a string input from the user, and want to parse it to a number, and would like to know how to do it. I would like to be able to accept arithmetic operations, like: '5+5'...
13
by: leaf | last post by:
How can i call arbirary functions at runtime, that with arbirary parameters and types? Can BOOST.Bind do that?
5
by: walter | last post by:
Hi there, I figured that there must be someone knew this-- I'm looking for a runtime expression evaluation engine for our business rule engine. A typical case is passing in a expression at runtime ...
32
by: Licheng Fang | last post by:
Basically, the problem is this: 'do' Python's NFA regexp engine trys only the first option, and happily rests on that. There's another example: 'oneself' The Python regular expression...
21
by: Steven T. Hatton | last post by:
I'm trying to improve my formal understanding of C++. One significant part of that effort involves clarifying my understanding of the vocabulary used to describe the language. This is from the...
32
by: silpau | last post by:
hi, i am a bit confused on expression evaluation order in expressions involving unary increment.decrement operators along with binary operators. For example in the following expression x...
0
balabaster
by: balabaster | last post by:
I don't know if anyone's got any clue about this, but I have the following expression evaluator which makes use of the CodeDom to evaluate a VB.NET expression at runtime. This gives the system...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
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.