I need to determine if an object has a specific type in the inheritance hierarchy, however I cannot find a good way to do this.
A very simple example of my classes:
Public Class Domain End Class Public Class DerivedOne Inherits Domain End Class Public Class DerivedTwo Inherits DerivedOne End Class Public Class DerivedThree Inherits Domain End Class
The following works, however, in my opinion, it is not very elegant. In addition, the more inheritance levels that are created, the more checks must be performed, and it would be easy to forget that this piece of code needs to be updated.
If GetType(T) Is GetType(Domain) OrElse _ GetType(T).BaseType Is GetType(Domain) OrElse _ GetType(T).BaseType.BaseType Is GetType(Domain) Then End If
Is there a way to get "Domain Type Anywhere in the T Inheritance Hierarchy"?
(Answers are welcome in C # or VB.NET)
UPDATE
One bit of vital information that I missed because of my own idiocy!
T is an object of type (from a generic class type)
source share