简体   繁体   中英

I want to put a comment that will let me get to a different block of code in c#

I think I could maybe use cref in the xml comments.

I also found a devious way using the nameof operator.

string fakeString = nameof( NewForm.HandleCommandLineArgments ); // use go to definition to get to NewForm.HandleCommandLineArgments

Any other ideas?

Update: I realize how to go to definition, ideally I wouldn't have to add "string fakeString". I thought cref is a bit of a bummer since I thought it could only be in xml comments at the top of the method, but you can put them anywhere.

I'm going with:

        /// <see cref="NewForm.HandleCommandLineArgments">
        PipeClient.SendSimpleStringMessage( "scriptcode", "[Arguments]" + commandLineArguments );

In Visual Studio 2017, you can just use Ctrl + T (or whatever shortcut is assigned to Edit/Go To All ) to go to any type. ReSharper has similar functionality even in earlier Visual Studio versions.

More should not be necessary; and variables like your fakeString are really a code smell (and may even cause build/maintenance issues due to "unused variable" diagnostics).

If it's something that is related to the method, it's also perfectly acceptable to include links in the XML Doc via <see cref="..."/> and/or <seealso cref="..."/> .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM