如何添加鼠标悬停摘要

10

我几乎可以肯定这将是一个非常简单的答案,但我似乎找不到它的任何地方。我们都知道当你将鼠标悬停在某个东西上时(比如一个字符串),会弹出一个小总结(如果已启用)。对于字符串,它会显示:

class System.String

表示文本为一系列Unicode字符。

当我将鼠标悬停在我的其中一个类上时,它只是显示:

class Namespace.Widget

我已经尝试了我找到的两个明显的例子:

/// <summary>
/// This summary does not work, I know it's for html documenting tools but thought it was worth a shot.
/// </summary>

并且:

// Summary:
//     This is what is in some of the base libraries, and does not work as well.

那么,我如何在鼠标悬停时添加摘要?


我刚刚使用了你的第一个例子,它有效了。 - Joel
是的,我刚刚让它工作了。我正在将我制作的各种类组合成一个库,在一个命名空间下,并且我正在使用来自我没有放入摘要的命名空间的类。 - Steve H.
6个回答

8
我不明白为什么你的第一次尝试不起作用。正是 <summary> 注释标签提供了你所说的“工具提示”...
/// <summary>
/// This text should automatically show up as the summary when hovering over
/// an instance of this class in VS
/// </summary>
public class MyClass
{
    public MyClass() {}      
}

public class MyClass2
{
    public MyClass()
    {
        //hovering over 'something' below in VS should provide the summary tooltip...
        MyClass something = new MyClass();
    }
}

如果您希望自动化一些评论的帮助,请尝试免费的GhostDoc。迄今为止最好的免费VS插件之一。

4

我刚刚发现的两个检查方法,可以避免在悬停时显示摘要:

请勿在摘要描述中使用&符号(&)或起始尖括号(<)。

断行:

    ///<summary>
    ///Class does this & that
    ///</summary>

请使用以下方式:

    ///<summary>
    ///Class does this AND that
    ///</summary>

断点:

    /// <summary>
    /// Checks if this < that
    /// </summary>

这样做可能能够运作,但不是一个良好的例子:

    /// <summary>
    /// Checks if this > that 
    /// </summary>

不要将///行彼此分离。

换行:

    /// <summary>
    /// This text will not show
    
    /// </summary>

换行:

    /// <summary>
    /// This text will also not show
    //  because THIS line only has 2 dashes
    /// </summary>

工作内容:

    /// <summary>
    ///
    /// This
    ///    
    /// is
    ///
    /// fine.
    ///
    /// </summary>

1
罪魁祸首对我们来说是符号 '<'。 - Kai Hartmann

1
三斜杠 XML 注释可用于在 Visual Studio 中创建 IDE 工具提示。特别是 "summary" 和 "exception" 很有效。 (其他像 "code" 这样的东西在我使用的 Visual Studio 版本中没有起作用。)
如果这对您不起作用,则可能是您的设置有问题。

异常处理不起作用,但得到了摘要。嗯,这只是表面修饰和边缘问题。 - Steve H.
如果exception元素的cref属性被设置,那么该异常将会在工具提示中列出。遗憾的是,元素内容将被忽略。所以我们可以说它只能半生不熟地工作。 :-) - Jeffrey L Whitledge

0

重置你在Visual Studio中的设置,它们似乎被搞乱了。为了让它显示出来,你需要使用第一个例子。


我也没有安装ctrl-f崩溃错误的热修复补丁,因为担心它会影响我的电脑上的其他东西。这可能与此有关吗? - Steve H.

0

你需要使用你的第一个语法,如果你在 Visual Studio 解决方案之外使用该类,你需要在项目属性中勾选生成 XML 文档文件。


0
除了以上的答案,您可以访问Microsoft docs link获取完整的标签列表,以便为您的类创建一个非常漂亮的摘要。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接