Documenting .NET Code
In this article I would like to introduce the special topic in .NET world: documentation. If you are new to programming and are working on a bigger project, please get used to documenting your code. There are many excellent guides out there explaining what good documentation is and you should read them. I will talk about .NET specific documentation feature, XML comments. This type of documenting is excellent in providing a guide to your created classes and their properties and methods. If you use XML comments, you can easily generate .chm files that look exactly the same as MSDN provided documentation! Isn't that awsome? Just use xml, compile the files using /doc switch and then use free tool like NDoc (http://ndoc.sourceforge.net/) to generate .chm files. NDoc actually can generate JavaDoc style documentation as well!
How XML Documentation works? Well, the reason why it is called XML is because it is in XML form. Don't worry if you don't know XML, it's not crucial here (although you should know XML as a programmer). I use XML Documentation to document all publicly visible members of my public classes. // or ' comments should still be there explaining your code. However the goal XML documentation is to provide more generic info. Let's take the following C# code as an example:
public LoadDate (string fileName)
How would I use XML documentation to explain what this method is doing? I would write this:
/// <summary>Loads xml from a file and initialized various data structures
Notice ///. This indicates that the comment is in XML format. In the example you saw two tags:
<summary> and <param> There are more:
How to generate the documentation from these comments? First of all, you have to set in your IDE (VS.NET or #Develop, or any other) that you want xml file generated that contains the documentation. In #Develop, go to Project, Project Options... and click on Configuration. One of the checkboxes will say "Generate xml documentation". Check it. I'm not sure about VS.NET setting, but it should be somewhere in Project settings or something. Once you have xml file generated, run NDoc, select the assembly that you want to document and its corresponding xml file and build documentation. Play around with that because when you will work on serious project, this will come in handy.