XML Documentation Comments using GhostDoc

In this article you will learn XML Documentation Comments using GhostDoc.

In C# we can write comment in 3 ways:

  • Single line Comments
  • Multi-line Comments
  • XML Documentation Comments

Single line Comments

  1. classProgram  
  2. {  
  3.     //This is an example of Auto Property Initializer in C# 6  
  4.     publicstringUserName   
  5.     {  
  6.         get;  
  7.     } = "Banketeshvar Narayan Sharma";  
  8. }  
class1.cs

Multi-line Comments
  1. /* This is an example of Dictionary initializer in C# 6 
  2. Where as in C# 5 we have to write like 
  3. { 101,"Banketeshvar Narayan Sharma"}, 
  4. { 102,"Rajnish Kumar Choudhary"}, 
  5. { 103,"Rajnish Kumar Choudhary"} 
  6. */  
  7. publicDictionary < intstring > _students   
  8. {  
  9.     get;  
  10. }   
  11. = newDictionary < intstring > ()   
  12. {  
  13.     [101] = "Banketeshvar Narayan Sharma", [102] = "Rajnish Kumar Choudhary", [103] = "Bhupesh"  
  14. };  
Class2.cs

XML Documentation Comments
  1. ///<summary>  
  2. ///  
  3. ///</summary>  
  4. ///<param name="emailId"></param>  
  5. ///<param name="subject"></param>  
  6. ///<param name="msgBody"></param>  
  7. ///<param name="listOfCcEmailIds"></param>  
  8. ///<param name="listofBccEmailIds"></param>  
  9. publicvoidSendMail(stringemailId, string subject, stringmsgBody, string[] listOfCcEmailIds, string[] listofBccEmailIds)   
  10. {  
  11.     //send mail.  
  12. }  
To write the above xml comment just type “///” and press enter it automatically generates these codes:
  1. ///<summary>  
  2. ///  
  3. ///</summary>  
  4. ///<param name="emailId"></param>  
  5. ///<param name="subject"></param>  
  6. ///<param name="msgBody"></param>  
  7. ///<param name="listOfCcEmailIds"></param>  
  8. ///<param name="listofBccEmailIds"></param>  
Class3.cs

But there is some extra effort with these XML comments: 
  1. We need to write Summary of Method/Class/property.
  2. I have to go to each method/class/property and write /// and then press enter.

If I have 50 classes and 5000 public entity (methods, classes, properties) then I have to Visit all those code snippet and write /// and then press enter 5K times and write Summary 5K times. But this can be eased by use of Visual Studio Extension GhostDoc.

XML Documentation Comments using GhostDoc

Go to Tools Menu - Extension and Update

Extension and Update

Select online tab & Search for GhostDoc.

GhostDoc

You can see that it’s showing a preview how it will make XML comments for C# & VB. Download and install it. You can visit the link here for complete details.

You can choose on which version you want to install it.

ghostdoc
Now see an example how it is fast & accurate.

My Class without XML Comment

  1. namespaceXMLDocumentationComments  
  2. {  
  3.     classGhostDocCommentDemo  
  4.     {  
  5.         publicintUserId  
  6.         {  
  7.             get;  
  8.         } = 1001;  
  9.         publicstringUserName  
  10.         {  
  11.             get;  
  12.         } = "Banketeshvar Narayan Sharma";  
  13.         publicstringEmailAddress  
  14.         {  
  15.             get;  
  16.         } = "bnarayan123@gmail.com";  
  17.   
  18.         publicvoidSendMail(stringemailId, string subject, stringmsgBody, string[] listOfCcEmailIds, string[] listofBccEmailIds)   
  19.         {  
  20.             //send mail.  
  21.         }  
  22.   
  23.         publicvoidSomeObject(double width, double height, double length, double weight, double volume, double density, boolisMetal, boolisConductor)   
  24.         {  
  25.             //do something  
  26.         }  
  27.   
  28.     }  
  29. }  
Class4.cs

Now I click on select all (Ctrl+A) and press Ctrl+Shift+D (GhostDoc default shortcut).

My Class with XML Comment done by GhostDoc
  1. namespaceXMLDocumentationComments   
  2. {  
  3.     ///<summary>  
  4.     ///  
  5.     ///</summary>  
  6.     classGhostDocCommentDemo  
  7.     {  
  8.         ///<summary>  
  9.         ///Gets the user identifier.  
  10.         ///</summary>  
  11.         ///<value>  
  12.         ///The user identifier.  
  13.         ///</value>  
  14.         publicintUserId   
  15.         {  
  16.             get;  
  17.         } = 1001;  
  18.         publicstringUserName  
  19.         {  
  20.             get;  
  21.         } = "Banketeshvar Narayan Sharma";  
  22.         publicstringEmailAddress   
  23.         {  
  24.             get;  
  25.         } = "bnarayan123@gmail.com";  
  26.   
  27.         ///<summary>  
  28.         ///Sends the mail.  
  29.         ///</summary>  
  30.         ///<param name="emailId">The email identifier.</param>  
  31.         ///<param name="subject">The subject.</param>  
  32.         ///<param name="msgBody">The MSG body.</param>  
  33.         ///<param name="listOfCcEmailIds">The list of cc email ids.</param>  
  34.         ///<param name="listofBccEmailIds">The listof BCC email ids.</param>  
  35.         publicvoidSendMail(stringemailId, string subject, stringmsgBody, string[] listOfCcEmailIds, string[] listofBccEmailIds)   
  36.         {  
  37.             //send mail.  
  38.         }  
  39.   
  40.         ///<summary>  
  41.         ///Somes the object.  
  42.         ///</summary>  
  43.         ///<param name="width">The width.</param>  
  44.         ///<param name="height">The height.</param>  
  45.         ///<param name="length">The length.</param>  
  46.         ///<param name="weight">The weight.</param>  
  47.         ///<param name="volume">The volume.</param>  
  48.         ///<param name="density">The density.</param>  
  49.         ///<param name="isMetal">if set to <c>true</c> [is metal].</param>  
  50.         ///<param name="isConductor">if set to <c>true</c> [is conductor].</param>  
  51.         publicvoidSomeObject(double width, double height, double length, double weight, double volume, double density, boolisMetal, boolisConductor)   
  52.         {  
  53.             //do something  
  54.         }  
  55.   
  56.     }  
  57. }  
Class5.cs