Click here to Skip to main content
15,909,518 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hi experts

I made a class

C#
public class Test
{
   public Name {get; set;}
   

   public void SetName()
   {
       // code
   }
}


You saw visual studio autocomplete for example when you type Conosole.Write then a tooltip is shown and says:
void Console.Write(string value) (+17 overload(s))
Write the specific string value to the standard output stream.

Exceptions:
   System.IO.IOException


I want something like this for my class. I used Description attribute but it did not work.
C#
public class Test
{
  [Description("Something1"]
   public Name {get; set;}
   
  [Description("Something2"] 
  public void SetName()
  {
       // code
  }
}


The question is: How can set some description for my mehtods and properties that it can be shown when the other programmers are using the class. like some built in classes.

thanks
Posted

C#
/// <summary>
/// Sets the name of the widget.
/// </summary>
public void SetName()
{
    // ...
}
 
Share this answer
 
Comments
Vartan Khachatourian 3-May-12 17:25pm    
thank you mark. simple but i didn't know.
Sergey Alexandrovich Kryukov 3-May-12 17:38pm    
I provided some more detail, please see. You can use XML with many detail which are automatically navigated. I referenced the documentation.
--SA
Vartan Khachatourian 3-May-12 17:48pm    
i read thanks
VJ Reddy 4-May-12 12:56pm    
Good answer. 5!
The question is not very clearly formulated, but I guess you need the documentation of your code to appear in Visual Studio Intellisense (which is not really auto-complete but some more advanced functionality).

You are looking in wrong direction: attributes are designed for very different purposes. The attributes can affect run-time behavior through Reflection, but you don't want to contaminate your code with something which is only needed during development, through Visual Studio or not. Therefore, Visual Studio supports completely different mechanism called XML Documentation Comments.

The idea is this: you comment some of your types and members with special comments which works like regular comments from the standpoint of C# but are processed in a special way by Visual Studio. Such comments are recognized by special comment delimiters:
C#
///
or
C#
/** 
...
*/


As you can see, in this way C# recognized such markup as comments. Start typing "///" one the line before a type or a member to be documented, and Visual Studio will create a minimalistic comment template for you.

Inside such comments, you can write specially formatted XML documentation to denote methods, parameters, cross-references, etc.

Please see:
http://msdn.microsoft.com/en-us/library/b2s063f7.aspx[^].

It creates the documentation in a special file which is, by default, is created and used only for Debug configuration, but you can change it in the project properties — please see the tab "Build", "XML Documentation file".

Enjoy,
—SA
 
Share this answer
 
v3
Comments
Vartan Khachatourian 3-May-12 17:47pm    
thank you sakryukov
Sergey Alexandrovich Kryukov 3-May-12 17:49pm    
You are very welcome.
Good luck, call again.
--SA
VJ Reddy 4-May-12 12:59pm    
Nice answer. attributes are designed for very different purposes is good point. 5!
Sergey Alexandrovich Kryukov 4-May-12 13:07pm    
Thank you, VJ.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900