I have a situation where one part of my code is generated through CodeExpressions and the other by the user himself (as in: the user simply writes his code, as usual, which I would take and add to my assembly when it compiles).
Is it possible to create an assembly containing both of these elements? Caution: these two approaches will contain partial classes, so they must be in the same assembly.
Another approach that I had in mind was perhaps translating both of these lines into a string representation, and then creating an assembly from that line, but I doubt that I can get the source code from the type generated by the user (at compile time).
While working on this idea, I can write the code generated by CodeExpressions into a text file and combine it with .cs files. The timeline will look like this:
- The user wrote his classes
- CodeDom tree is installed programmatically
- User creates a project.
- CodeDom generates source text to text file
- The program reads the contents of user-defined
.cs files - The program reads the generated text file
- Program combines these two
- The program creates a new
.dll from the combined source code
I could skip the (redundant) steps of writing and reading my generated CodeDom source to a text file and just writing it to memory, of course. In fact, the easiest way is to use Pre-Processed T4 templates and load the results of these templates into memory and compile the assembly from this line.
As you can see, this is very dirty, but now it looks the most doable. I looked through all the options that could make this easier?
Background :
I am creating a library that will create an assembly with classes that are user defined. The way this works is in the following order:
- User links to my library in his project
- User creates a new instance of
TinyTypeSetup - User adds Tiny Type definitions to it.
- The user runs the program
- The program generates an assembly of the specified types through CodeDom
What I'm trying to add now is the ability for the user to create their own source files and immediately add these files to the assembly that is being generated. This will allow the user to specify partial classes with their own methods, on top of those that I generate myself.
c # .net-assembly code-generation codedom
Jeroen vannevel
source share