472,127 Members | 1,751 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 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 4196
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Douglas Buchanan | last post: by
8 posts views Thread by Brian Blais | last post: by
13 posts views Thread by leaf | last post: by
5 posts views Thread by walter | last post: by
21 posts views Thread by Steven T. Hatton | last post: by
reply views Thread by leo001 | last post: by

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.