Emit Code into exisitng instance at runtime

  • Thread starter Thread starter Robert Lario
  • Start date Start date
R

Robert Lario

I understand how to create a new class in memory, but I want to "Instrument
" an exisiting object. for example when an object is passed to a function
called foo, from within foo I want to add a new bool attribute to that
instance/type (if it has not already been added).

anybody have any ideas on how to solve this?
 
Robert,

This is a bad idea for all sorts of reasons, even if one excludes the sheer
difficulty of implementing this within the CLR. A much better approach
would be to add a properties collection to the target class at design time,
thereby allowing dynamic addition of new properties as necessary at run
time. Is there any particular reason this approach would not work for you?

Nicole
 
Back
Top