views:

155

answers:

8

One thing that always bugged me, is that I do not see the base type in Visual Studio. I just stumbled on this, because I tried to cast a System.Windows.Forms.MenuItem to a System.Windows.Forms.Control

In eclipse the "intellisense" (or whatever it is called) shows me while exploring the members of a class for each member from which base class it is inherited.

In Visual Studio I cannot see the base class, even if I use the Objectbrowser or the help.

The only solution I found is to use at runtime:

Console.WriteLine(obj.GetType.BaseType)
Console.WriteLine(obj.GetType.BaseType.BaseType)
Console.WriteLine(obj.GetType.BaseType.BaseType.BaseType)
...

until I reach System.Object(). Is there a way to query the base type tree of a class at Design Time?

+1  A: 

Use the class view. Press Ctrl+W, Ctrl+C.

The class view will show you the base types and many things besides.

Tor Haugen
A: 

The online documentation / MSDN gives this for every .NET class

Eric
+3  A: 
Fredrik Mörk
That does the trick. Base types where hidden in my setup.
SchlaWiener
A: 

Object Browser lists the base-type, interfaces and derived types (or it does for me - it could be one of many add-ons...)

Marc Gravell
+2  A: 

View -> Class View

Usually I just do the "Go to Definition" in the context menu though.

Albinofrenchy
+1 for "Go to Definition"
Danko Durbić
and +1 from my side, too
SchlaWiener
A: 

You can use the class view (ctrl+w, c). For types that are not your own, you can use reflector.

JP Alioto
A: 

While debugging the watch window will tell you what the base class is.

the_ajp
A: 

Reflector is a great tool for looking at a classes hierarchy, including it's base classes.

You don't have to have the source code, and it can browse through everything in the framework too.

Simon P Stevens