0

Let's say I have a WinForm App...written in C#.

Is it possible?

4 Answers 4

1

After all, put my eye on Iron Python.

Sign up to request clarification or add additional context in comments.

Comments

0

C# is not interpreted, so unlike javascript or other interpreted languages you can't do that natively. You can go four basic routes, listed here in order of least to most complex...

1) Provide a fixed set of operations that the user can apply. Parse the user's input, or provide checkboxes or other UI elements to indicate that a given operation should be applied.

2) Provide a plugin-based or otherwise dynamically defined set of operations. Like #1, this has the advantage of not needing special permissions like full trust. MEF might come in handy for this approach: http://mef.codeplex.com/

3) Use a dynamic c# compilation framework like paxScript: http://eco148-88394.innterhost.net/paxscriptnet/. This would, in theory, allow you to compile small c# snippets on demand.

4) Use IL Emit statements to parse code and generate your operations on the fly. This is by far the most complex solution, likely requires full trust, and is extremely error prone. I don't recommend it unless you have some very obscure requirements and sophisticated users.

1 Comment

well. the best solution is to write own simple scripting language, that'd not be too hard. or.. will consider embedded VBScript
0

The CSharpCodeProvider class will do what you want. For a (VERY outdated, but still working with a few tweaks) example of its use, check out CSI.

Comments

0

If you are willing to consider targeting the Mono runtime, the type Mono.CSharp.Evaluator provides an API for evaluating C# expressions and statements at runtime.

1 Comment

@Kirk - yes, it is pretty much full-featured, you can get an idea of all of the expressions it can parse, compile, and execute on the fly by checking out the C# interactive shell which is based on this API: mono-project.com/CsharpRepl (indeed, even when I'm doing .NET development, I have Mono installed with the interactive shell up most of the time so I can do exploratory programming).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.