![]() |
Languages »
C / C++ Language »
General
Intermediate
Quick C# Documentation using XMLBy irfan patelThis article shows how to create documentation in C# in a simple and fast way. Like my previous articles, this one too focuses beginner to intermediate level. |
C#, XML.NET 1.0, .NET 1.1, .NET 2.0, Win2K, WinXP, Win2003VS.NET2003, Dev
|
|
Advanced Search |
|
|
|
||||||||||||||||
This article shows how to create documentation in C# in a simple and fast way. Like my previous articles, this one too focuses beginner to intermediate level. Advance developers please scroll to the bottom of this article. Remember the days when programmers used to work hard to do the documentation? Trust me, it's a huge difference nowadays. Now, all a programmer need to do is to embed the XML documentation right into the code and let Visual Studio .NET perform the rest.
Note: If you are very new to XML, click here to checkout my previous article on XML walkthrough.
To start with, just follow the instructions step by step.
Replace the code in the class with the following:
using System;
namespace TestXMLdoc
{
/// <summary>
/// This project shows how to create XMl documentation in C#
/// </summary>
public class TestXMLdoc
{
/// <summary>
/// m_iTestVar is a module level test variable for storing int
/// </summary>
private int m_iTestVar;
/// <summary>
/// m_sTestVar is a module level test variable for storing string
/// </summary>
private string m_sTestVar;
/// <summary>
/// TestXMLdoc is the constructor
/// </summary>
public TestXMLdoc()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
/// TestReturnBack is a test method which
/// simply takes a name and returns it back.
/// </summary>
/// <param name="sName"></param>
/// <returns></returns>
public string TestReturnBack(string sName)
{
return "Your name is " + sName;
}
}
}
Note: If you are not using the Visual Studio .NET IDE, you should go for the first one from the following optionss:
csc testXMLdoc.cs /doc:testXMLdoc.xml
(or)
Unlike Java, Microsoft Visual C# generates XML documentation instead of HTML, and as we know about XML, it's mould-able and later can be used anywhere else we need. The following is a list of tags along with their description which can be used in creation of XML documentation.
This will textually include provided code in a single line.
E.g.: <c> int i = 0 ; </c>
This will textually include provided code in multiple lines (snippet).
This will include a code example.
This will force the compiler whether it matches a possible exception.
This will fetch the documentation from an external file. Same as #include in scripting languages.
This will insert a list into the documentation file.
This specifies the parameters of the method and makes the compiler verify it.
This will mark a parameter.
This will determine the access permissions.
This will include a descriptive text.
This will mark the return value of a member.
It is a reference to a related item.
This is similar to the 'See also' section of the MSDN help.
A summary of the member item. Normally, Visual Studio .NET prepares this automatically along with its close tag the moment you type.
This is nothing but a property.

Wasn't that fun? It was.. I know. But that was just a trailer, let's see the whole movie.


That's the result of your patience, hard work and cooperation.
Note: The above example was for people who need a tool to suffice their minimum requirements. For advance documentation, you would like to opt for a more sophisticated tool like NDoc Code Documentation Generator for .NET.
NDoc generates class library documentation from .NET assemblies and the XML documentation files generated by the C# compiler (or with an add-on tool for VB.NET). And the output looks like the following:

NDoc uses pluggable documenters to generate documentation in several different formats, including the MSDN-style HTML Help format (.chm), the Visual Studio .NET Help format (HTML Help 2), and MSDN-online style web pages.
You can download the latest version: NDOC 1.3 Beta or NDOC 1.2.
Thanks to Ms. Manisha Mahajani for reviewing the article for errors.
Njoi programming!! ;)
| You must Sign In to use this message board. | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 30 Aug 2004 Editor: Smitha Vijayan |
Copyright 2004 by irfan patel Everything else Copyright © CodeProject, 1999-2009 Web18 | Advertise on the Code Project |