0

Is it possible to get in .NET summary data somehow?

 /// <summary>
 /// I need to get it programatically
 /// </summary>
 private void MethodA()
 {
 }
NoWar
  • 36,338
  • 80
  • 323
  • 498
  • 1
    But the answer there uses parsing of the CSC compiler generated XML comment file, and the answer here uses DTE functions at runtime (within the VisualStudio environment). – w5l Jan 23 '13 at 15:37

2 Answers2

1

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).

w5l
  • 5,341
  • 1
  • 25
  • 43
1

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

Community
  • 1
  • 1
Carra
  • 17,808
  • 7
  • 62
  • 75