Let’s say I have the following class hierarchy: TaskViewer inherits from ListViewer<Task> which in turn inherits from ViewerBase.
If I debug into a method that is declared in ViewerBase and look at this.GetType(), it correctly returns TaskViewer. However, I cannot find a property or method which will return me the generic parameter that was used in the inheritance, i.e. Task. Obviously if I was in the context of TaskViewer or ListViewer<T> then I would easily know this.
I can see that it was Task by looking at the BaseType.FullName property, but I’ve been through the list and nothing I can see identifies itself as having used that generic argument.
How might I get the original generic parameter from within this method in the root class?
You can access the generic argument of the base type as follows (assuming only a single type argument).
In
ViewerBaseyou would usebut it seems quite weired to look at the generic type arguments of a derived class in the base class. You cannot know waht the actual type is, hence not if it has generic arguments at all. Could you tell something about your usage scenario?