none
Customizing Reflected Information and Call Interception RRS feed

  • Question

  • I am wondering if anyone knows whether the following can be accomplished and, if so, what the best approach is to doing so:

    Given a custom type T I want to be able to customize reflected type information and provide a synthesized implementation of the type at runtime. 

    For example, suppose I have defined a Person class with properties FirstName and LastName.
    Next, I define a DecoratedPerson class, not subclassed from person, that has a concretely implemented FullName property that simply concatenates the person's first and last name. Now, I want a client to be able to ask an instance of the DecoratedPerson class, through reflection, the persons first and last name. Well, unless the decorator specifically declares and implements these properties, the client obviously won't be able to find them through reflection and obtain their values.

    When a client reflects over the DecoratedPerson class to obtain the properties, I need a way to return the PropertyInfo elements from both the Person class and the DecoratedPerson class.

    I think there might be a way to accomplish this via use of the TypeDelegator class in conjunction with subclassing DecoratedPerson from ContextBoundObject, though I'm not sure how specifically to "register" the type delegator (if this is even possible) with the runtime so that whenever someone reflects over the decorator the operations on the subclassed TypeDelegator get called.

    Any pointers on this would be appreciated, thanks.
    Friday, February 19, 2010 4:28 PM

Answers

All replies