In C# we can write comment in 3 ways:
- Single line Comments
- Multi-line Comments
- XML Documentation Comments
Single line Comments
- classProgram
- {
-
- publicstringUserName
- {
- get;
- } = "Banketeshvar Narayan Sharma";
- }
class1.cs
Multi-line Comments -
-
-
-
-
-
- publicDictionary < int, string > _students
- {
- get;
- }
- = newDictionary < int, string > ()
- {
- [101] = "Banketeshvar Narayan Sharma", [102] = "Rajnish Kumar Choudhary", [103] = "Bhupesh"
- };
Class2.cs XML Documentation Comments -
-
-
-
-
-
-
-
- publicvoidSendMail(stringemailId, string subject, stringmsgBody, string[] listOfCcEmailIds, string[] listofBccEmailIds)
- {
-
- }
To write the above xml comment just type “///” and press enter it automatically generates these codes:
Class3.cs But there is some extra effort with these XML comments:
- We need to write Summary of Method/Class/property.
- 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
Select online tab & Search for 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.
Now see an example how it is fast & accurate.
My Class without XML Comment
- namespaceXMLDocumentationComments
- {
- classGhostDocCommentDemo
- {
- publicintUserId
- {
- get;
- } = 1001;
- publicstringUserName
- {
- get;
- } = "Banketeshvar Narayan Sharma";
- publicstringEmailAddress
- {
- get;
- } = "[email protected]";
-
- publicvoidSendMail(stringemailId, string subject, stringmsgBody, string[] listOfCcEmailIds, string[] listofBccEmailIds)
- {
-
- }
-
- publicvoidSomeObject(double width, double height, double length, double weight, double volume, double density, boolisMetal, boolisConductor)
- {
-
- }
-
- }
- }
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 - namespaceXMLDocumentationComments
- {
-
-
-
- classGhostDocCommentDemo
- {
-
-
-
-
-
-
- publicintUserId
- {
- get;
- } = 1001;
- publicstringUserName
- {
- get;
- } = "Banketeshvar Narayan Sharma";
- publicstringEmailAddress
- {
- get;
- } = "[email protected]";
-
-
-
-
-
-
-
-
-
- publicvoidSendMail(stringemailId, string subject, stringmsgBody, string[] listOfCcEmailIds, string[] listofBccEmailIds)
- {
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
- publicvoidSomeObject(double width, double height, double length, double weight, double volume, double density, boolisMetal, boolisConductor)
- {
-
- }
-
- }
- }
Class5.cs