Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I add links in comments to a code block in Visual studio?

Can I add links in comments to a code block in Visual studio ?

For example:

// block 1
class class1
{
}

// block 2
class class2
{
    // review [___class1]
}

[___class1] is a link for class1

Thanks in advance.

like image 565
Homam Avatar asked Sep 21 '10 12:09

Homam


People also ask

How do you comment a block of code in Visual Studio?

Comment Code Block Ctrl+K+C/Ctrl+K+U If you select a block of code and use the key sequence Ctrl+K+C, you'll comment out the section of code. Ctrl+K+U will uncomment the code.

How do you add a HyperLink to VS code?

Select an existing control or drag and drop a control from the Visual Studio toolbox onto the design surface. Right-click the control to open the Properties Window. In the Properties Window, set the HyperLink property to mailto: any valid e-mail address.


1 Answers

You can bookmark your code in Visual Studio, but that's stored in your user options file and isn't normally checked into source control. I don't know of a way to link to portions of code from other portions of code.

Your best bet might be to use document comments and a <see> tag:

/// <see cref="Fully.Qualified.Type.Name"/>

But that's going to be limited to fully qualified locations, i.e. types, methods, fields, and properties. A particular block (say, an if statement within a method) is right out, and it'll only link the documentation for that method/whatever to another documentation section, and then only if you generate the documentation using a tool like Sandcastle.

One other thing you might consider, and this is a very bad hack, is to use file hyperlinks, like so:

// file://c:/code/file.cs

There are caveats:

  • You have to use the full path name. Relative paths won't work, so it's going to be tied directly to your code, and won't work if you remap your source repository to another location
  • Visual Studio will stop at the first space, so spaces in file names or folder names will cause it to fail
  • You can't link to a portion of the code, just the whole file.
like image 199
Randolpho Avatar answered Sep 28 '22 16:09

Randolpho