{"id":21,"date":"2010-01-02T22:00:42","date_gmt":"2010-01-03T04:00:42","guid":{"rendered":"http:\/\/www.insomnihack.com\/?p=21"},"modified":"2010-01-02T22:00:42","modified_gmt":"2010-01-03T04:00:42","slug":"c-xml-comments-tools-of-the-trade","status":"publish","type":"post","link":"https:\/\/www.insomnihack.com\/?p=21","title":{"rendered":"C# XML Comments &#8211; Tools of the Trade"},"content":{"rendered":"<p>A few months back, someone at work commented on the amount of XML comments in my C# code. I admit, I do tend to prefer more comments in my C# code. Unless I&#8217;m working on the quickest and dirtiest of throw-away apps, I try to comment my classes as if they were going to be used as a framework by other developers. I find that the process of creating the documentation actually helps me focus on what the class or method should actually be doing.<\/p>\n<p>Also, I&#8217;ve been on the receiving end of poorly documented code.<\/p>\n<div id=\"attachment_170\" style=\"width: 391px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.insomnihack.com\/wp-content\/uploads\/comment_your_code_rant.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-170\" class=\"size-full wp-image-170 \" title=\"Comment Your Damn Code, Already!\" src=\"http:\/\/www.insomnihack.com\/wp-content\/uploads\/comment_your_code_rant.jpg\" alt=\"\" width=\"381\" height=\"254\" srcset=\"https:\/\/www.insomnihack.com\/wp-content\/uploads\/comment_your_code_rant.jpg 381w, https:\/\/www.insomnihack.com\/wp-content\/uploads\/comment_your_code_rant-300x200.jpg 300w\" sizes=\"(max-width: 381px) 100vw, 381px\" \/><\/a><p id=\"caption-attachment-170\" class=\"wp-caption-text\">Cut the next poor bastard a break and comment your code.<\/p><\/div>\n<p>To be clear, I&#8217;m not talking about comments in the body of a method itself. I&#8217;ve found that if the body of a method requires more than a few comments to describe what it&#8217;s doing, that method probably needs to be refactored. I&#8217;m talking specifically about the XML comments (or JavaDoc comments in the case of Java source code) of the public and protected members of my non-private classes.<\/p>\n<p>This post describes the tools I use on a regular basis to produce good code documentation. These tools are primarily targeted towards C# developers working in Visual Studio. I may do another post later to describe tools useful for recreating this process in other languages and platforms. If you&#8217;re a VB.NET programmer, there&#8217;s a good <a title=\"Documenting Your Code With XML Comments by Lisa Feigenbaum\" href=\"http:\/\/msdn.microsoft.com\/en-us\/magazine\/dd722812.aspx\">MSDN article<\/a> on XML comments in Visual Basic you might want to check out.<\/p>\n<h3>GhostDoc<\/h3>\n<p><a title=\"GhostDoc\" href=\"http:\/\/submain.com\/products\/ghostdoc.aspx\">GhostDoc<\/a> is a free Visual Studio add-in originally created by <a title=\"Roland Weigelt Homepage\" href=\"http:\/\/roland-weigelt.de\/\">Roland Weigelt<\/a>. It was recently acquired by <a title=\"SubMain Homepage\" href=\"http:\/\/submain.com\/\">SubMain<\/a>, but they&#8217;ve stated that it is their intention to keep it free.<\/p>\n<p style=\"text-align: center;\">\n<div id=\"attachment_39\" style=\"width: 485px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.insomnihack.com\/wp-content\/uploads\/ghostdoc_options.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-39\" class=\"size-full wp-image-39   \" title=\"GhostDoc Options\" src=\"http:\/\/www.insomnihack.com\/wp-content\/uploads\/ghostdoc_options.png\" alt=\"Options screen for GhostDoc\" width=\"475\" height=\"432\" srcset=\"https:\/\/www.insomnihack.com\/wp-content\/uploads\/ghostdoc_options.png 660w, https:\/\/www.insomnihack.com\/wp-content\/uploads\/ghostdoc_options-300x272.png 300w\" sizes=\"(max-width: 475px) 100vw, 475px\" \/><\/a><p id=\"caption-attachment-39\" class=\"wp-caption-text\">Configuration screen for GhostDoc<\/p><\/div>\n<p>Visual Studio 2008 already helps a little with XML documentation by inserting the tags for you when you type three forward slashes (i.e. \/\/\/) and hit Enter.<\/p>\n<p>[csharp]<br \/>\n\/\/\/ &lt;summary&gt;<br \/>\n\/\/\/<br \/>\n\/\/\/ &lt;\/summary&gt;<br \/>\n\/\/\/ &lt;param name=&quot;id&quot;&gt;&lt;\/param&gt;<br \/>\n\/\/\/ &lt;returns&gt;&lt;\/returns&gt;<br \/>\npublic string GetName(int id)<br \/>\n{<br \/>\n    return string.Empty;<br \/>\n}<br \/>\n[\/csharp]<\/p>\n<p>GhostDoc does you one better by filling out the empty XML comment tags with text based on code element type, parameters, name, and other contextual information. The default keyboard shortcut is Ctrl-Shift-D. You can also get at GhostDoc via the context menu.<\/p>\n<p>[csharp]<br \/>\n\/\/\/ &lt;summary&gt;<br \/>\n\/\/\/ Gets the name.<br \/>\n\/\/\/ &lt;\/summary&gt;<br \/>\n\/\/\/ &lt;param name=&quot;id&quot;&gt;The id.&lt;\/param&gt;<br \/>\n\/\/\/ &lt;returns&gt;&lt;\/returns&gt;<br \/>\npublic string GetName(int id)<br \/>\n{<br \/>\n    return string.Empty;<br \/>\n}<br \/>\n[\/csharp]<\/p>\n<p>Usually, a bit of modification to the comments generated by GhostDoc is all I need.<\/p>\n<h3>Agent Smith<\/h3>\n<p><a href=\"http:\/\/code.google.com\/p\/agentsmithplugin\/\">Agent Smith<\/a> is a C# coding style validation plug-in for <a href=\"http:\/\/www.jetbrains.com\/resharper\/\">ReSharper<\/a> hosted on <a href=\"http:\/\/code.google.com\/\">Google Code<\/a>. You need to have ReSharper installed in order to use it. In addition to naming validation and smart paste, Agent Smith provides some valuable features for writing XML commenting including comment validation, re-flow, and spell check.<\/p>\n<div id=\"attachment_160\" style=\"width: 521px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.insomnihack.com\/wp-content\/uploads\/agent_smith_settings1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-160\" class=\"size-full wp-image-160\" title=\"Agent Smith - Code Style Settings\" src=\"http:\/\/www.insomnihack.com\/wp-content\/uploads\/agent_smith_settings1.png\" alt=\"\" width=\"511\" height=\"264\" srcset=\"https:\/\/www.insomnihack.com\/wp-content\/uploads\/agent_smith_settings1.png 851w, https:\/\/www.insomnihack.com\/wp-content\/uploads\/agent_smith_settings1-300x155.png 300w\" sizes=\"(max-width: 511px) 100vw, 511px\" \/><\/a><p id=\"caption-attachment-160\" class=\"wp-caption-text\">Agent Smith - Code Style Settings<\/p><\/div>\n<div id=\"attachment_161\" style=\"width: 521px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.insomnihack.com\/wp-content\/uploads\/agent_smith_settings2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-161\" class=\"size-full wp-image-161\" title=\"Agent Smith - Naming Convention Settings\" src=\"http:\/\/www.insomnihack.com\/wp-content\/uploads\/agent_smith_settings2.png\" alt=\"\" width=\"511\" height=\"317\" srcset=\"https:\/\/www.insomnihack.com\/wp-content\/uploads\/agent_smith_settings2.png 851w, https:\/\/www.insomnihack.com\/wp-content\/uploads\/agent_smith_settings2-300x186.png 300w\" sizes=\"(max-width: 511px) 100vw, 511px\" \/><\/a><p id=\"caption-attachment-161\" class=\"wp-caption-text\">Agent Smith - Naming Convention Settings<\/p><\/div>\n<div id=\"attachment_162\" style=\"width: 521px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.insomnihack.com\/wp-content\/uploads\/agent_smith_settings3.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-162\" class=\"size-full wp-image-162\" title=\"Agent Smith - Spell Check Settings\" src=\"http:\/\/www.insomnihack.com\/wp-content\/uploads\/agent_smith_settings3.png\" alt=\"\" width=\"511\" height=\"317\" srcset=\"https:\/\/www.insomnihack.com\/wp-content\/uploads\/agent_smith_settings3.png 851w, https:\/\/www.insomnihack.com\/wp-content\/uploads\/agent_smith_settings3-300x186.png 300w\" sizes=\"(max-width: 511px) 100vw, 511px\" \/><\/a><p id=\"caption-attachment-162\" class=\"wp-caption-text\">Agent Smith - Spell Check Settings<\/p><\/div>\n<div id=\"attachment_163\" style=\"width: 521px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.insomnihack.com\/wp-content\/uploads\/agent_smith_settings4.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-163\" class=\"size-full wp-image-163\" title=\"Agent Smith - Dictionaries\" src=\"http:\/\/www.insomnihack.com\/wp-content\/uploads\/agent_smith_settings4.png\" alt=\"\" width=\"511\" height=\"317\" srcset=\"https:\/\/www.insomnihack.com\/wp-content\/uploads\/agent_smith_settings4.png 851w, https:\/\/www.insomnihack.com\/wp-content\/uploads\/agent_smith_settings4-300x186.png 300w\" sizes=\"(max-width: 511px) 100vw, 511px\" \/><\/a><p id=\"caption-attachment-163\" class=\"wp-caption-text\">Agent Smith - Dictionaries<\/p><\/div>\n<p>I use this plug-in primarily for pestering me about naming conventions and for the the spell checking. I&#8217;ve tried other Visual Studio plug-ins for spell checking, but by far this is the one I like the best.<\/p>\n<p><a href=\"http:\/\/www.insomnihack.com\/wp-content\/uploads\/agent_smith_spellcheck.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-174\" title=\"Agent Smith - Spell Check\" src=\"http:\/\/www.insomnihack.com\/wp-content\/uploads\/agent_smith_spellcheck.png\" alt=\"\" width=\"409\" height=\"126\" srcset=\"https:\/\/www.insomnihack.com\/wp-content\/uploads\/agent_smith_spellcheck.png 409w, https:\/\/www.insomnihack.com\/wp-content\/uploads\/agent_smith_spellcheck-300x92.png 300w\" sizes=\"(max-width: 409px) 100vw, 409px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tools for producing XML documentation for C# code.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[11,13,25],"_links":{"self":[{"href":"https:\/\/www.insomnihack.com\/index.php?rest_route=\/wp\/v2\/posts\/21"}],"collection":[{"href":"https:\/\/www.insomnihack.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.insomnihack.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.insomnihack.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.insomnihack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=21"}],"version-history":[{"count":0,"href":"https:\/\/www.insomnihack.com\/index.php?rest_route=\/wp\/v2\/posts\/21\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.insomnihack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=21"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.insomnihack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=21"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.insomnihack.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=21"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}