如何为自定义创建的类获取智能感知?

发布于 2024-12-17 17:44:29 字数 226 浏览 1 评论 0原文

当你输入“这个”时。 ,您通常会获得当前班级的所有例程、事件等。当您只是站在长列表中的一个例程而不选择其中一个时,您通常会在它旁边看到一个描述。

我怎样才能做到这一点? 假设我有一个名为 CAR 的类,它有两个例程:speed_up() 和brake()。 如何让使用我的类的人在输入时看到这两个函数的描述:

CAR mycar = new CAR();
mycar.

When you type "this." , you usually get all the routines, events, and more... of the current class you are in. And when you simply stand over one of the routines in the long list without choosing one, you usually get a description next to it.

How can I do that ?
Let assume I have a class called CAR with two routines: speed_up(), and brake().
How can I make the person using my class to see a description of the two functions when he types:

CAR mycar = new CAR();
mycar.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

飘过的浮云 2024-12-24 17:44:30

为您的班级及其成员提供 XML 注释,这些注释将显示在智能感知。在 Visual Studio 中执行此操作的最简单方法是在要添加注释的内容上方键入 ///

例如:

/// <summary>
/// Class level summary documentation goes here.</summary>
/// <remarks>
/// Longer comments can be associated with a type or member through
/// the remarks tag.</remarks>
public class TestClass : TestInterface
{
    /// <summary>
    /// Store for the name property.</summary>
    private string _name = null;

    /// <summary>
    /// The class constructor. </summary>
    public TestClass() { }

    /// <summary>
    /// Description for SomeMethod.</summary>
    /// <param name="s"> Parameter description for s goes here.</param>
    /// <seealso cref="System.String">
    /// You can use the cref attribute on any tag to reference a type or member 
    /// and the compiler will check that the reference exists. </seealso>
    public void SomeMethod(string s)
    {
    }
}

上述内容可在此处找到。


另请参阅:如何让 XML 注释出现在不同的项目 (dll) 中?

Give your classes and their members, XML comments, which will appear in intellisense. The easiest way of doing this in visual studio is by typing /// above what you want to add comments to.

For example:

/// <summary>
/// Class level summary documentation goes here.</summary>
/// <remarks>
/// Longer comments can be associated with a type or member through
/// the remarks tag.</remarks>
public class TestClass : TestInterface
{
    /// <summary>
    /// Store for the name property.</summary>
    private string _name = null;

    /// <summary>
    /// The class constructor. </summary>
    public TestClass() { }

    /// <summary>
    /// Description for SomeMethod.</summary>
    /// <param name="s"> Parameter description for s goes here.</param>
    /// <seealso cref="System.String">
    /// You can use the cref attribute on any tag to reference a type or member 
    /// and the compiler will check that the reference exists. </seealso>
    public void SomeMethod(string s)
    {
    }
}

The above was found here.


See also: How do you get XML comments to appear in a different project (dll)?

瞎闹 2024-12-24 17:44:30

您应该对每个类型构造(即类、方法、属性...)使用 Visual Studio 中可用的 XML 文档格式。

要访问它,请在声明之前的行中键入 ///。

例如:

  ///
  public void Method(string p){...

你会得到类似的信息:

  /// <summary>
  /// 
  /// </summary>
  /// <param name="p"></param>
  public void Method(string p){...

如果你输入 ///<您甚至可以获得可用 XML 元素的列表,例如备注或示例
有关详细信息,请参阅 http://msdn.microsoft.com/en-us/杂志/cc302121.aspx

You should use the XML documentation format available in Visual studio for every type constructs (ie class, methods, properties...)

To access it, type /// on the line before your declaration.

For instance:

  ///
  public void Method(string p){...

you will get something like:

  /// <summary>
  /// 
  /// </summary>
  /// <param name="p"></param>
  public void Method(string p){...

if you type ///< you will even get the list of available XML elements, like remarks or exemple
For more informations, see http://msdn.microsoft.com/en-us/magazine/cc302121.aspx

你げ笑在眉眼 2024-12-24 17:44:30

您可以这样发表评论:

/// <summary>
/// This sppeds up the car
/// </summary>
public void speed_up()
{ }

You can put comments like this:

/// <summary>
/// This sppeds up the car
/// </summary>
public void speed_up()
{ }
泪痕残 2024-12-24 17:44:30

你必须这样注释:

/// <summary>
/// This is my function.
/// </summary>
/// <param name="myParameter">This parameter is very important.</param>
/// <returns>It returns always 42.</returns>
public int MyFunction(string myParameter)
{
    return 42;
}

你可以描述函数

的用法以及参数的含义.如果函数有返回值,可以用标签来描述它。支持一些 mor 标签,当您在三个 \ 之后写下评论时,Visual Studio 会列出这些标签。

You have to put a comment on it like this:

/// <summary>
/// This is my function.
/// </summary>
/// <param name="myParameter">This parameter is very important.</param>
/// <returns>It returns always 42.</returns>
public int MyFunction(string myParameter)
{
    return 42;
}

You can describe the usage of the function <summary> and the meaning of the paramaters <param name="">. If the function has a return value, you can describe it with the tag <returns>. There are some mor tags supported, the will be listed by visual studio, when you write your comment after three \.

我家小可爱 2024-12-24 17:44:30

尝试通过键入 /// 向您的方法添加摘要,并像下面一样填写,

/// <summary>
/// This is my speed up method
/// </summary>
public void speed_up(){ ...}

您可以对每个方法和属性执行此操作,以便它在 Intellisense 中有意义地显示意图。

Try adding a summary to your methods by keying in /// and fill up like below

/// <summary>
/// This is my speed up method
/// </summary>
public void speed_up(){ ...}

you can do this for each of the methods and properties, so that it meaningfully displays the intent in Intellisense.

妞丶爷亲个 2024-12-24 17:44:30

您需要为方法添加文档注释。您可以通过键入“///”或使用 Visual Studio 插件手动执行此操作。如果您遵循良好的命名约定 GhostDoc 添加将对您有很大帮助。

You need to add document comments for the methods. you can do this manually by typing '///' or using visual studio addin. If you follow good naming conventions GhostDoc adding will help you lot on this.

笨死的猪 2024-12-24 17:44:29

在类或方法之上,而不是“//”注释。如果您使用“///”三斜杠(也称为 XML 注释),它会执行一个快捷方式,以允许您填写有关您正在注释的类或方法的信息。

然后,这会出现在您的代码中,

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void Method(object sender, EventArgs e)

当您通过智能感知访问类或方法时,描述就会出现。

Above a class or a method, rather than a "//" comment. if you do a "///" triple slash ( otherwise known as an XML comment ), it performs a short cut to allow you to fill information out about the class or method you are commenting on.

This then appears in your code as such

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void Method(object sender, EventArgs e)

When you then access the class or method through intellisense thats when the description will appear.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文