How to get intellisense for custom created classes

2020-08-11 10:41发布

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.

7条回答
再贱就再见
2楼-- · 2020-08-11 11:22

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.

查看更多
不美不萌又怎样
3楼-- · 2020-08-11 11:24

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)?

查看更多
Emotional °昔
4楼-- · 2020-08-11 11:34

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 \.

查看更多
劳资没心,怎么记你
5楼-- · 2020-08-11 11:37

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.

查看更多
Summer. ? 凉城
6楼-- · 2020-08-11 11:38

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.

查看更多
太酷不给撩
7楼-- · 2020-08-11 11:39

You can put comments like this:

/// <summary>
/// This sppeds up the car
/// </summary>
public void speed_up()
{ }
查看更多
登录 后发表回答