Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic code generation

I am currently developing an application where you can create "programs" with it without writing source code, just click&play if you like.

Now the question is how do I generate an executable program from my data model. There are many possibilities but I am not sure which one is the best for me. I need to generate assemblies with classes and namespace and everything which can be part of the application.

  1. CodeDOM class: I heard of lots of limitations and bugs of this class. I need to create attributes on method parameters and return values. Is this supported?

  2. Create C# source code programmatically and then call CompileAssemblyFromFile on it: This would work since I can generate any code I want and C# supports most CLR features. But wouldn't this be slow?

  3. Use the reflection ILGenerator class: I think with this I can generate every possible .NET code. But I think this is much more complicated and error prone than the other approaches?

  4. Are there other possible solutions?

EDIT: The tool is general for developing applications, it is not restricted to a specific domain. I don't know if it can be considered a visual programming language. The user can create classes, methods, method calls, all kinds of expressions. It won't be very limitating because you should be able to do most things which are allowed in real programming languages. At the moment lots of things must still be written by the user as text, but the goal at the end is, that nearly everything can be clicked together.

like image 561
codymanix Avatar asked Nov 17 '09 11:11

codymanix


1 Answers

You my find it is rewarding to look at the Dynamic Language Runtime which is more or less designed for creating high-level languages based on .NET.

It's perhaps also worth looking at some of the previous Stack Overflow threads on Domain Specific Languages which contain some useful links to tools for working with DSLs, which sounds a little like what you are planning although I'm still not absolutely clear from the question what exactly your aim is.

like image 186
glenatron Avatar answered Oct 13 '22 06:10

glenatron