Emit Code into exisitng instance at runtime

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert Lario

    #1

    Emit Code into exisitng instance at runtime

    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?


  • Nicole Calinoiu

    #2
    Re: Emit Code into exisitng instance at runtime

    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


    "Robert Lario" <lario@nospam.i nherit.com> wrote in message
    news:eA4x$fGgDH A.2484@TK2MSFTN GP09.phx.gbl...[color=blue]
    > I understand how to create a new class in memory, but I want to[/color]
    "Instrument[color=blue]
    > " 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?
    >
    >[/color]


    Comment

    Working...