【问题标题】:C# Visual Studio Intellisense without XML tags没有 XML 标记的 C# Visual Studio Intellisense
【发布时间】:2019-11-28 15:51:36
【问题描述】:

有没有办法让 Visual Studio 2019 (Enterprise) 识别 Intellisense 的非 XML 文档字符串,以便当您将鼠标悬停在它上面时,它会显示摘要、参数等?具体来说,与在 C# SDK 中格式化文档字符串的方式相同。

例如,对于Thread.Sleep(millisecondsTimeout),它具有以下文档字符串:

    //
    // Summary:
    //     Suspends the current thread for the specified number of milliseconds.
    //
    // Parameters:
    //   millisecondsTimeout:
    //     The number of milliseconds for which the thread is suspended. If the value of
    //     the millisecondsTimeout argument is zero, the thread relinquishes the remainder
    //     of its time slice to any thread of equal priority that is ready to run. If there
    //     are no other threads of equal priority that are ready to run, execution of the
    //     current thread is not suspended.
    //
    // Exceptions:
    //   T:System.ArgumentOutOfRangeException:
    //     The time-out value is negative and is not equal to System.Threading.Timeout.Infinite.

这是出现的内容:Intellisense tooltip

我发现 XML 标记 (<param>millisecondsTimeout</param>) 的想法在查看代码时会损害可读性,并且想知道是否有一种方法可以使它更类似于 Java 的 JavaDoc,这并不难阅读。

【问题讨论】:

标签: c# visual-studio intellisense


【解决方案1】:

这不能直接在 VS 中完成,如前所述,您需要扩展此类功能。但我不知道。

另一方面,即使是 .NET 框架本身也使用 XML cmets。您为Thread.Sleep(millisecondsTimeout) 提到的内容正是当您在方法调用上按 F12 时 VS 从元数据中呈现给您的内容。其实这个方法有如下XML注释:

<summary>
Suspends the current thread for the specified number of milliseconds.
</summary>
<param name="millisecondsTimeout">
The number of milliseconds for which the thread is suspended. If the value of the <paramref name="millisecondsTimeout" /> argument is zero, 
the thread relinquishes the remainder of its time slice to any thread of equal priority that is ready to run. 
If there are no other threads of equal priority that are ready to run, execution of the current thread is not suspended.
</param>
<exception cref="T:System.ArgumentOutOfRangeException">
The time-out value is negative and is not equal to <see cref="F:System.Threading.Timeout.Infinite" />.
</exception>

Visual Studio 和 Intellisense 从您可以在 C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.X\mscorlib.xml 等位置找到的 XML 文件中获取它。

【讨论】:

  • 谢谢!我不知道 .NET 框架也使用 XML。我想我会坚持使用 XML 标记,然后只是为了与框架和我的团队似乎使用的内容保持一致。
猜你喜欢
  • 2010-09-10
  • 1970-01-01
  • 1970-01-01
  • 2016-01-09
  • 1970-01-01
  • 1970-01-01
  • 2015-11-24
  • 1970-01-01
  • 2010-11-02
相关资源
最近更新 更多