I’ve got an export process which takes an annotated class as an output file definition (much like Linq-To-Entities)
A class looks something like this:
<ExportDefinition(Name:="Some Export Format")>
Public Class SomeExportFormat
Overridable Property Id As Integer
<DisplayName("Customer Name")>
Overridable Property CustomerName As String
End Class
Properties are overridable as I sometimes have to proxy.
I need to add functionality which allows the specification of transient formats (A WCF call to request export of specific data with a one-time format).
To avoid re-writing a lot of the export code, I’d like to take the definition I’m passed via WCF and define a new class.
Is my best bet to use System.CodeDom.Compiler or is there a more elegant solution?
Personally, I’d be looking at
TypeBuilder, but I’m a little bit… unbalanced, and ready to hop intoILGenerator. But yes, You can create new subclasses that way. Watch out, though – WCF and EF won’t automatically accept your types. Most inheritance-aware libraries (which includes WCF and EF) will hate dynamic subclasses, since they weren’t expecting them and will treat them as completely unexpected data.