The C# compiler csc.exe has a /doc option that outputs an external XML file having your triple-slash comments. This XML file is used by documentation generators (e.g. Sandcastle does this kind of thing).
That same option to export XML comments is available from Visual Studio. To set this compiler option in the Visual Studio development environment:
- Open the project's Properties page. For details, see How to: Set Project Properties (C#, J#).
- Click the Build property page.
- Modify the XML Documentation File property.
You can load up this XML file using an XML parser from the .NET framework, access the Types in it, and grab the related comments from around them.
You're right the C# compiler doesn't compile comments into the meta data. However Microsoft created triple-slash comments for export ability, so you can get a handle to them.
Instructions for processing the XML file are here on MSDN.
As an example, I enable the XML output file option and documented the following method:
/// <summary>
/// This method parses the given name for
/// capitalization.
/// </summary>
public void ParseStringCase(string name)
{
// behaviour of method...
}
It produces the following XML in a file in the bin/ folder....
<?xml version="1.0"?>
<doc>
<assembly>
<name>WindowsFormsApplication3</name>
</assembly>
<members>
<member name="M:WindowsFormsApplication3.Form1.ParseStringCase(System.String)">
<summary>
This method parses the given name for
capitalization.
</summary>
</member>
</members>
</doc>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…