|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionMost of us will have experienced the dread of updating documentation at some point or other. C# and Visual Studio .NET (VS.NET) give us the ability to maintain code and documentation in the same file, which makes the whole process a lot easier. VS.NET does this by taking specially marked and structured comments from within the code and building them into an XML file. This XML file can then be used to generate human-readable documentation in a variety of forms including web pages, MSDN style documentation and Intellisense within the code window. Configure XML CommentingVS.NET produces XML comments by taking specially marked and structured comments from within the code and building them into an XML file. This XML file can then be used to generate human-readable documentation in a variety of forms including web pages, MSDN style documentation and Intellisense within the code window. The first thing you need to do is enable the XML commenting feature for your VS.NET project.
With this enabled, your XML comment data file will be rebuilt each time you build your project. Any problems that occur when trying to generate the file will not prevent a build but will be flagged in the VS.NET Task List. Assuming you do not have compile warnings set to errors.
VS.NET Task List flagging XML commenting error. With that enabled you can start to use the special XML tags in your procedure “headers”. To get you started, place the cursor on the line directly above a procedure’s definition. Once there, press the “/” key three times, this will automatically insert a summary tag into your code. If the procedure had any arguments there should now be a param tag for each one. /// <summary>
///
/// </summary>
/// <param name="data"></param>
public void SaveData(ref DataSet data)
{
}
The /// <summary>
/// Connects to the database and attempts to apply
/// all adds, updates and deletes
/// </summary>
/// <param name="data">a dataset, passed by reference,
/// that contains all the
/// data for updating>/param>
public void SaveData(ref DataSet data)
{
}
This
It is clear from just this feature, how useful XML commenting is. When you include a reference to a .NET project that has XML commenting enabled, the XML documentation file we named earlier is copied over along with the binary to the current project’s \bin directory. This gives you the intellisense across assemblies. The summary tag is the most basic of tags. The list below is the complete set currently supported by VS.NET. The ones marked with a * are the ones I feel are the most useful and the ones we will be dealing in the following examples.
MSDN Style Documentation and NDOCWe have taken the intellisense format as far as it will go, but there is much more we can do with MSDN style documentation. There is a tool that comes with VS.NET that you will find at “Tools|Build Comment Web Pages…” which will take your C# XML comments from source files and generate linked HTML files. This comes straight out of the box so should not be totally disregarded. But if you want to create easy-to-use, helpful, cross-referenced and attractive documentation, then I can strongly recommend the free, open source tool NDoc. The screenshot below is taken from a compiled help file produced from NDoc and is an example of the quality it can produce.
The two routines below will show the correct usage for most of the XML comment
tags we saw earlier. The /// <summary>
/// Gets or sets the age of the person involved in the accident
/// </summary>
/// <value>Age of the claimant.</value>
/// <remarks> The value must be numeric.
/// </remarks>
/// <exception cref="System.ApplicationException">Thrown when a non-
/// numeric value is assigned.</exception>
public string Age
{
}
This
I have drawn attention to areas in the picture and their corresponding XML comment tags. /// <summary>
/// Connects to the database and attempts to apply all adds,
/// updates and deletes
/// </summary>
/// <seealso cref="Adjuster.BusinessServices.Accident"/>
/// <param name="data">a dataset, passed by reference,
/// that contains all the
/// data for updating</param>
/// <example> This sample shows how to call the SaveData
/// method from a wireless device.
/// <code>
///
///AccidentCRUD accCRUD = new Adjuster.BusinessServices.AccidentCRUD();
///accCRUD.SaveData(ref ds);
///
///</code>
///</example>
///<permission cref="System.Security.PermissionSet">Everyone
///can access this method.</Permission>
public void SaveData(ref DataSet data)
{
}
This
Again I have drawn attention to areas in the picture and their
corresponding XML comment tags. The With the combination of NDoc and VS.Net & C#’s ability to produce these comments you can get great technical documentation at a level so close to the code, that there is absolutely no excuse for it not telling it as it is.
|
||||||||||||||||||||||