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 then take and add to my assembly when he compiles).
Is it possible to generate an assembly that contains both of these items? Caveat: these two approaches will contain partial
classes so they have to be in the same assembly.
Another approach I had in mind was by perhaps translating both of these to a string representation and then generating the assembly from that string, but I doubt I can get the source code from a type generated by the user (at compile-time).
Working on that idea I could write the CodeExpressions generated code to a textfile and combine that with the .cs
files. A timeline would look like this:
- User wrote his classes
- CodeDom tree is setup programmatically
- User builds the project
- CodeDom generates source to a textfile
- Program reads contents of the user-defined
.cs
files - Program reads generated textfile
- Program combines these two
- Program creates a new
.dll
from the combined source code
I could skip the (redundant) steps of writing and reading of my generated CodeDom source to a textfile and simply write it to memory as well, ofcourse. In fact, it might just be easiest to use Pre-Processed T4 templates and load the results of these templates into memory and compile an assembly from that string.
As you can see, this is very messy but right now it looks the most feasible one. Have I looked over any options that might make this easier?
I'm creating a library that will create an assembly with classes that are defined by the user. The way this works is in the following order:
- User references my library in his project
- User creates new
TinyTypeSetup
instance - User adds Tiny Type definitions to it
- User runs program
- Program generates assembly from the given types through CodeDom
What I am trying to add now is the possibility for the user to create his own source files and add those files immediately to the assembly that gets generated. This would allow the user to specify partial classes with his own methods, on top of those I generate myself.