Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting parent class' name using Reflection

How can I get the name of the parent class of some class using Reflection?

like image 215
AndreyAkinshin Avatar asked Oct 06 '09 09:10

AndreyAkinshin


People also ask

How do I find parent class names?

The parent() method is used to return all ancestor of the selected elements. Check if ancestor (parent) class exist then it returns the class name otherwise returns not exist.

How do I get fields from parent class?

Now how can i get fields of parent class in this case 'a'. You can use getField() with public fields. Otherwise, you need to loop through parent classes yourself.

How do you refer parent classes in C#?

You would need to add a property to your Production class and set it to point back at its parent, this doesn't exist by default. Show activity on this post. In the Production constructor you can assign this to a private field or a property. Then Production will always have access to is parent.


1 Answers

Like so:

typeof(Typ).BaseType.Name 
like image 176
Maximilian Mayerl Avatar answered Oct 02 '22 20:10

Maximilian Mayerl