Fares
Fares

Reputation: 364

How to get intellisense for custom created classes?

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.

Upvotes: 13

Views: 12953

Answers (7)

Eilistraee
Eilistraee

Reputation: 8290

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

Upvotes: 3

Damith
Damith

Reputation: 63065

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.

Upvotes: 1

V4Vendetta
V4Vendetta

Reputation: 38200

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.

Upvotes: 2

George Duckett
George Duckett

Reputation: 32418

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

Upvotes: 8

Fischermaen
Fischermaen

Reputation: 12458

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

Upvotes: 2

misha
misha

Reputation: 2889

You can put comments like this:

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

Upvotes: 2

Chris
Chris

Reputation: 3162

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.

Upvotes: 26

Related Questions