简体   繁体   English

我想发表评论,让我在 C# 中获得不同的代码块

[英]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.我想我可以在 xml 注释中使用 cref。

I also found a devious way using the nameof operator.我还发现了一种使用 nameof 运算符的狡猾方法。

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".更新:我意识到如何去定义,理想情况下我不必添加“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.我认为 cref 有点令人失望,因为我认为它只能在方法顶部的 xml 注释中,但您可以将它们放在任何地方。

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.在 Visual Studio 2017 中,您只需使用Ctrl + T (或分配给Edit/Go To All任何快捷方式)即可转到任何类型。 ReSharper has similar functionality even in earlier Visual Studio versions.即使在早期的 Visual Studio 版本中,ReSharper 也具有类似的功能。

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).和像您的fakeString这样的变量fakeString是一种代码异味(甚至可能由于“未使用的变量”诊断而导致构建/维护问题)。

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="..."/> .如果它与方法相关,那么通过<see cref="..."/>和/或<seealso cref="..."/>在 XML Doc 中包含链接也是完全可以接受的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将代码块放入 c# 中的 function 中? - How can I put the code block into a function in c#? Visual C#Express 2010评论代码块的快捷方式? - Visual C# Express 2010 Shortcut to comment a code block? C#不会让我在方法的开头放置某些变量。我不明白为什么不 - C# won't let me put certain variables at the beginning of method. I don't understand why not 我想得到一个字段值让我们说(名称)来自C#Mvc中的数据表, - I want to get A field Values let say (Name) From Data Table in C# Mvc, 如何阻止或 - How to block <b> or <i> in a comment box using a regex in C# c#我想更新sql不同的值但错误帮助我 - c# I want update sql different Value but Error Help me 将vb中的代码块转换为c#时,应该将其放在循环的哪一部分? - What part from the block of code in vb when converting it to c# should i put in the loop? 为什么我的 C# 编译器 (Visual Studio) 不允许我使用 try 块执行此操作? - Why doesn't my C# compiler (Visual Studio) let me do this with a try block? 我想将 XERO 集成到 WebAPI C# 有人可以为我提供 oauth2 的示例代码吗 - I want to integrate XERO to WebAPI C# Can someone provide me sample code for oauth2 为什么当我想通过 C# 运行 GAMS 代码时,visual studio 给我错误? - Why does visual studio gives me error when I want to run the GAMS code via C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM