I need to extend instances of different types at runtime. In most cases, I need to work with instances of the source type, but in some cases I need to create an extension wrapper around those types that add a couple of pieces of contextual information. Something in the lines of the following (which is not really valid .NET / C # code ... but this illustrates the point):
public abstract class BaseClass {
Another example of this might be Microsoft Entity Framework v4.0 or nHibernate. Both of these structures provide dynamically expanded instances of the types of your entities, wrapping them internally to provide the runtime hooks needed to constantly update the data context / object / session with the changes made to the entity instances. My needs are not so complex, and the generic script described above will work beautifully, at least one way to combine generics and dynamic typing.
Anyway, I hope someone knows how to achieve the above scenario. Or maybe even better, someone knows a better solution. I don't care about the idea of โโdynamically expanding this type at runtime (it doesn't have the same meaning as in the EF / nHibernate script). At the moment, this is the only thing I can really think of, this will provide me with the information that I need in the processor for each type passed to DoProcessing.
source share