views:

46

answers:

2

I want to allow the users to define a formula based on two variables. Say I have a Quantity and Value and I want to allow the users of my app to write something like

Quantity*20+Value*0,005

in a textbox and pass the result back to the C# app. I thought of embedding the IronPython interpreter in my app, but I'm not sure it's worth the effort. Is this the way to go or should I consider another option?

Update

To clarify, users may also write more complex formulae like:

if Value > 10000:
    return Value*0,05
elif Value > 1000:
    return Value*0,02
else
    return 0
+2  A: 

I think I'll go this way. Embedding the Python runtime is easy enough and the syntax is really simple for users to write simple scripts.

Carles
I don't think you can go wrong here. Embedding the runtime is really simple, and other alternatives are guaranteed to be more difficult.
Ryan Riley
+1  A: 

If that is all that you want to do, to evaluate a simple expression you could just dynamically compile C# code:

http://msdn.microsoft.com/en-us/magazine/cc188948.aspx

It's something like 20 lines of code.

Adal
I think I prefer the IronPython option... It's easier.
Carles