By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,201 Members | 1,617 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,201 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.