6
I’m using reflection to know if one class inherits another, what I found was this:
bool herda = typeof(A).IsAssignableFrom(typeof(B));
But I want to do it in the variable getting your type.
Here’s the following definition I need:
public class A { }
public class B : A { }
public class Principal
{
public static void Main(string[] args)
{
B b = new B();
// quero saber se classe B herda classe A através da variável b
}
}
Related:Difference between the use of typeof and is
– Jéf Bueno
A tip: almost always do not need this, this information you have without asking for the code. It has several features that people use because they don’t understand what the code really needs, these resources exist for quite rare cases, it may be yours, but statistically it is more likely that it is not.
– Maniero