Is it possible to view summaries of class methods which are instantiated using interface?

Viewed 80

I have an interface which is implemented by lots of classes. I have set summaries for methods in these classes and also in the interface. The problem is I am instantiating class objects as follows:

MyInterface object = new MyClass();

This is a design rule so I have to instantiate class objects using the interface. However, I have more in-depth summaries set in class methods for the developers. Is it possible to make the developer who will use these interface and classes view the summaries set in class instead of the ones in interface? My concern is with C#. Thanks in advance.

1 Answers

The answer is: no, this is not currently possible out-of-the-box with VS.

Consider your example. MyInterface object = new MyClass();

At design time, object has a type of MyInterface, not MyClass. One could make the argument that the IDE could do a tiny bit more analysis to figure out the type is MyClass.

Now consider this code:

MyInterface object = new MyClass();
if (some_runtime_variable == false) { object = new MyClassToo(); }

Now what should the tooltip read? The IDE has no way to know what the value of some_runtime_variable is going to be. And nothing prevents hundreds of classes from implementing MyInterface, so an argument of "show all the docs" isn't going to fly.

You could, theoretically, write a VS add-on that would accomplish your goals, but you would need to address the issue I've outlined above.

Related