I am using VB.Net. I have an object class called clsA(of T as clsB). Depending on what T is, I want to do different things. Let’s say that clsC and clsD both inherit clsB and therefore can be used for T.
If I have an instance of clsA(of clsC), how can I get the inside type (i.e. clsC) using reflection?
Reflection is a .NET technology – it’s not specific to either VB.NET or C#.
Given an object, o, use
o.GetType().GetGenericArguments()(0)However, it’s probably a bad idea to explicitly vary your behavior based on the type. If you need to do different things based on class “A” vs. class “B”, then you should use virtual methods or properties, and override them in the derived types: