How to print the entire base type of an object?

I have an object, I would like to print all its parent type to Object? How to do it?

+6
source share
3 answers

If you are only interested in the class hierarchy:

Type type = obj.GetType(); while (type != null) { Console.WriteLine(type.Name); type = type.BaseType; } 
+5
source
 var t = obj.GetType(); while (t != null) { Console.WriteLine(t.Name); t = t.BaseType; } 
+2
source
 Type currentType = obj.GetType(); while (currentType != null) { Console.WriteLine(currentType.ToString()); currentType = currentType.BaseType; } 
+1
source

Source: https://habr.com/ru/post/906405/


All Articles