TweeZz
TweeZz

Reputation: 4919

Is it possible to add a reference or link to a method or property?

I tend to write quite some comments within 1 method. Once in a while I'm referring to another method or property in another class. It goes something like:

// if you uncomment the next line, then please make sure you check 'MyClass.SomeMethod'.

[update]
In an attempt to hopefully give a less code smelly comment. Maybe it might go something like (thank you @Weston):

/// <summary>
/// Adds two numbers  
/// See method Subtract for the opposite of add.
/// See also Multiply
/// </summary>

Maybe something similar could be written inside a method? The answer of @weston helps me further. [/update]

I'm looking for something which would make it clickable. Is there any existing extension / plugin / add on which can do something like this?

Upvotes: 1

Views: 324

Answers (2)

weston
weston

Reputation: 54801

If you have resharper then a documentation comment solution + F12 to navigate to definition does work.

    /// <summary>Adds two numbers
    /// <para>See <see cref="Subtract"/> for the opposite of add.</para>
    /// See also <seealso cref="Multiply"/>
    /// </summary>
    public int Add(int x, int y){

Cursor on Subtract or Multiply then F12 will take you there. Note that I have tried with resharper off and it doesn't work.

What's more, resharper will apply renaming refactorings in these comments.

Upvotes: 2

Clint
Clint

Reputation: 6220

This is pretty much a bad idea anyway, if you're having to include notes about other areas of the code that might break / change functionality if you do something in one place then your code may need rethinking.

Aside from that I'd recommend looking in the visual studio extension gallery, there may be an extension that suits your needs.

Failing that look up the guide to extending visual studio, an extension that does this probably wouldn't be too difficult to put together yourself.

Upvotes: 1

Related Questions