Alan Wayne
Alan Wayne

Reputation: 5384

How to implement "Go To Definition" for application elements with leading description?

Visual Studio 2017 C#

In writing code, I find it very useful to right-click on a system element and select "Go To Definition". This very neatly shows the element's properties and methods with the leading "..." being nicely expandable to give a full text definition of the immediately following property/method.

How could I duplicate this help function for my own code? In particular, I wish to condense a leading descriptions into "..." prior to the following property/method.

TIA

Example display on "Inkcanvas[metadata]":

enter image description here

Upvotes: 2

Views: 229

Answers (2)

Grant Howard
Grant Howard

Reputation: 135

When you select Go To Definition, Visual Studio will show metadata if it couldn't find the source code. And the expandable "..." only appear in metadata viewer.
To achieve something like this, let's say we have a library containing the following code:

namespace Library
{
    public class MyClass
    {
        public void MyMethod() { }
    }
}

1. Add some documentation for it:

namespace Library
{
    /// <summary>
    /// Documentation for MyClass
    /// </summary>
    public class MyClass
    {
        /// <summary>
        /// Documentation for MyMethod
        /// </summary>
        /// <param name="parameter">Parameter decription</param>
        public void MyMethod(int parameter) { }
    }
}

2. Then go to Project Properties -> Build and check XML documentation file.
3. Compile the library.
4. In another solution, add reference for the compiled Library.
5. Write some code using class from Library:

namespace UseTheLibrary
{
    class Program
    {
        static void Main(string[] args)
        {
            new MyClass().MyMethod(0);
        }
    }
}

6. Now use the Go To Definition.
And you can see "..." in the metadata viewer. Screenshot Of course expandable: Expand

Upvotes: 1

Furkan Kambay
Furkan Kambay

Reputation: 760

  1. The metadata view
    • Since you have the project opened in Visual Studio, Go to definition will navigate to the source file for that symbol. If you want just the metadata view, then you can reference the project's DLL in another project (in a solution where you don't have this one opened), and it will show you just the metadata since you can't see the source code as you only have the DLL.
  2. The ... part

Upvotes: 2

Related Questions