473,390 Members | 1,538 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,390 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 4261
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.