R
Richard Dutton
I would like to be able to modify a type at runtime so that I can add an IL
prologue and epilogue to its methods (either to implement some kind of
aspect-oriented programming framework, or a simple profiling tool). I know
that a simlpe way to achieve the same behaviour, at least for a type's
virtual methods, is to derive a new type and add my code before and after
calls to the inner object's methods, but for my own edification I'd like to
try to actually inject the code into the existing type.
TypeBuilder, MethodRental and their cohorts in Reflection.Emit look like
they are capable of performing such injection, but only on types in a
dynamic assembly so my questions are these:
Is it at all possible to use Reflection.Emit.*Builder on types in an
assembly that has been loaded from disc (and acquired using
Assembly.GetExecutingAssembly, for example).
If not, is it possible somehow to copy an Assembly into an AssemblyBuilder
(or Module into ModuleBuilder and so on) in order to modify that.
Is there another dynamic way to perform the injection (i.e. not using
il(d)asm).
Many thanks,
Richard Dutton
prologue and epilogue to its methods (either to implement some kind of
aspect-oriented programming framework, or a simple profiling tool). I know
that a simlpe way to achieve the same behaviour, at least for a type's
virtual methods, is to derive a new type and add my code before and after
calls to the inner object's methods, but for my own edification I'd like to
try to actually inject the code into the existing type.
TypeBuilder, MethodRental and their cohorts in Reflection.Emit look like
they are capable of performing such injection, but only on types in a
dynamic assembly so my questions are these:
Is it at all possible to use Reflection.Emit.*Builder on types in an
assembly that has been loaded from disc (and acquired using
Assembly.GetExecutingAssembly, for example).
If not, is it possible somehow to copy an Assembly into an AssemblyBuilder
(or Module into ModuleBuilder and so on) in order to modify that.
Is there another dynamic way to perform the injection (i.e. not using
il(d)asm).
Many thanks,
Richard Dutton