Is it possible to get in .NET summary data somehow?
/// <summary>
/// I need to get it programatically
/// </summary>
private void MethodA()
{
}
Is it possible to get in .NET summary data somehow?
/// <summary>
/// I need to get it programatically
/// </summary>
private void MethodA()
{
}
Use the EnvDTE
namespace to get the current code element, you can then access the Comment
and DocComment
properties.
You need to add references: How to: Add References to Automation Namespaces is a good place to start.
Then you need to get access to the EnvDTE
object: How to: Get References to the DTE and DTE2 Objects.
From there it depends on where your code is located. Through EnvDTE
you have to find the project item it's declared in, browse to it, and then access the comment properties.
You can get the current document through the ActiveDocument
property on your DTE
object, which will return a Document
. If the Document
is part of a project, you can grab the ProjectItem
, and through there access the CodeElements
collection.
From there it gets slightly complicated. A CodeElement
does not have a comment property. You can use CodeElement.Kind
to see what specific kind of code element you're looking at: CodeClass
, CodeFunction
, etc... After deciding on the correct type, and casting to it, you can finally access the comment text. For navigating through your code elements, remember that they can have Children
(eg. Properties in a Class).
You can also extract the documentation to an xml file and then use regular xml parsing on that file.
More info: C# getting interface method comments