Dynamic code generation

I am currently developing an application in which you can create “programs” with it without writing the source code, just click & play if you want.

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

  • CodeDOM class: I heard about the many limitations and errors of this class. I need to create attributes for method parameters and return values. Is it supported?

  • Create C # source code programmatically, and then call CompileAssemblyFromFile on it: this will work, as I can generate any code I want, and C # supports most of the CLR functions. But won't it be slow?

  • Use the reflection class ILGenerator: I think that with this I can generate all possible .NET codes. But I think this is much more complicated and error prone than other approaches?

  • Are there other possible solutions?

EDIT: This tool is common for application development, it is not limited to a specific domain. I do not know whether it can be considered a visual programming language. The user can create classes, methods, method calls, all kinds of expressions. This will not be very limiting, because you should be able to do most of the things that are allowed in real programming languages. At the moment, it should still be written by the user as text, but the goal at the end is that almost everything can be clicked together.

+5
source share
6 answers

, , , ..

, , DSL, , , , .

+4

" " , (, ). : - "". , (, DataTable .., ) ..

Expression; .NET 4.0, .

+2

# , . # .

+1

, System.Reflection.Emit.

, . Emit (, , ..). , ILGenerator op- MSIL . , , :

  • ILDasm op- .
+1

, CodeDOM, , "", " ".

, 2 .

0
source

I would repeat the others in that 1) the compiler is fast, and 2) "Click and Play" should be simple enough so that no widget added to a bunch of widgets can make it illegal. >

Good luck. I am skeptical that you can reach point (2) for anything other than truly toy-level programs.

0
source

All Articles