Julien Rousseau
Julien Rousseau

Reputation: 985

How to find out which interfaces a .net class implements?

Ok, so I've been learning c# and .net recently and one thing that seems to be missing from the c# documentation on http://msdn.microsoft.com/ that is present in the java documentation (e.g. ArrayList doc) is that a java class's documentation will say something like:

All Implemented Interfaces: Serializable, Cloneable, Iterable, Collection, List, RandomAccess Direct Known Subclasses: AttributeList, RoleList, RoleUnresolvedList

This allows me to find out which interfaces it implements and possibly discover interfaces I didn't know of yet. I can further click on an interface and get information on which classes implement it (in the standard classes anyway) and which interfaces extend it:

All Superinterfaces:
     Iterable<E>
All Known Subinterfaces:
     BeanContext, BeanContextServices, BlockingDeque<E>, BlockingQueue<E>, ...
All Known Implementing Classes:
     AbstractCollection, AbstractList, AbstractQueue, AbstractSequentialList, ...

When using Microsoft's documentation I only get the base classes and possibly subclasses:

System.Object 
  System.MarshalByRefObject
    System.IO.Stream
      More...

"More..." being a link with a list of subclasses.

Is there a way in the documentation to find what interfaces a .Net class implements in a similar way that we can in the Java documentation?

Edit: I'm using Visual Studio Express and the publicly available documentation on MSDN so I suppose that the answer might be: yes you can, but you must pay up first for [full visual studio|MSDN subscription|...].

Upvotes: 2

Views: 1596

Answers (4)

P.Brian.Mackey
P.Brian.Mackey

Reputation: 44275

Resharper has Go to Base Symbols. you can use:

  • CTRL + U
  • Right click the class name > Navigate > Base Symbols
  • Resharper menu > Navigate > Base Symbols

This command allows you to navigate up the inheritance hierarchy to a base type [including classes and interfaces] or method of the current symbol.

Here's a sample from a XAML.cs file

enter image description here

Upvotes: 0

dav_i
dav_i

Reputation: 28107

In Visual Studio, place the caret on the thing you want to know about e.g. bool and press F12

It will show you the definition of the thing you pressed F12 on, so for bool:

namespace System
{
    // Summary:
    //     Represents a Boolean value.
    [Serializable]
    [ComVisible(true)]
    public struct Boolean : IComparable, IConvertible, IComparable<bool>, IEquatable<bool>
    {
        // Summary:
        //     Represents the Boolean value false as a string. This field is read-only.
        public static readonly string FalseString;
...

Additionally you can open the Code Definition Window (View>Code Definition Window, Ctrl+W,D) which will show the above in a window - no button presses needed!

Upvotes: 1

Ilya Chernomordik
Ilya Chernomordik

Reputation: 30195

Resharper has a feature that allows that as well. If you press Ctrl+Shift+F1 then you can see a documentation about the class with full list of interfaces that it implements. You can decompile it using resharper to achieve the same result (though it's a little bit too much for what you need).

Upvotes: 0

RB.
RB.

Reputation: 37182

Documentation

Check out the Syntax section (e.g. for IObservableCollection(T)) in the documentation.

This gives the class declaration, including implemented interfaces

[SerializableAttribute]
public class ObservableCollection<T> : Collection<T>, 
    INotifyCollectionChanged, INotifyPropertyChanged

ILSpy

However, for classes for which documentation is not available, you can use a dissassembler such as ILSpy. Simply select a class, and it will show all base-types and derived types. enter image description here

Object Browser Finally, you can also use the Object Browser in Visual Studio (I'm not 100% sure it's in Express). ViewObject Browser. This will show the base-types as you require.

enter image description here

Upvotes: 4

Related Questions