Getting A Method Description Using Reflection
Is it possible to get the comment description of a method or property using reflection. E.g When you use intellisense in Visual Studio to scroll through methods available to object there is a label which describes what the method does. Ho开发者_开发技巧w can I access this data programmatically using reflection? your thoughts are much appreciated. Tony
No. The method description is defined in an XML file (with the same name as the declaring assembly) extracted from XML comments in the source code. Visual Studio uses that XML file to load those stuff. The information is nowhere in the assembly metadata and naturally, it's not available using reflection:
/// <summary> Method description </summary>
public void Something() { ... }
When the C# compiler is invoked with /doc
switch, it extracts the XML tags and puts it in the XML file. Visual Studio checks if an XML file is available along the referenced assembly and displays the description as appropriate.
Intellisense is showing you the additional comments data (generated from your /// comments, and typically stored in an xml file next to your dll/exe), which is not available to reflection, so no. You would have to load this manually. You can access the [Description]
attribute, but this is not the same.
If you open the properties for the project you want documentation for then select the build tab.
One of the last properties ypu can set i Xml documentation file, here you can specify in which file to store the documentation in.
The file is just xml so parsing that ought to be a trivial matter.
精彩评论