I have a little library which relies hugely on Emitting classes and methods.
I want to migrate it to .Net Standard because it doesn't use any unmanaged things so can be easily running on whatever OS. But when I ran Portability checker on my solution, it showed that everything is OK with my Expression
generator part, but it is whining on Emit
usages.
Here is analysis for net452
,netstandard1.6
and netstandard2.0
.
My question is if there is some modern and recommended way to generate classes at runtime which is supported by .Net Standard or I can just forget about porting my library to it?
Well, I found that nowadays in
.Net Standard
we have expression trees to generate standalone delegates and old fashionedEmit
(available withSystem.Reflection.Emit
andSystem.Reflection.Emit.Lightweight
namespaces) for the rest. Unfortunly, we lost bridge between the former and the latter (I meanLambdaExpression.CompileToMethod
, see question).So generaly there is almost same code generation power as in full desktop
.Net
until you don't need to generate types at runtime (implement some interface on the fly, for example). In this case you are forced to emit IL manually.