Extract comments from C # source file

Does anyone know of any tools that allow you to extract comments directly from a .cs file into some plain text or even to the clipboard? Even better if such a tool can work at the method level.

I am not looking for something like Sandcastle that works during build time. I am looking for something that works with single source files. Basically, I need to copy a fragment of method signatures and related comments into a text file, but I get bored of deleting "///" and rearranging the lines. I would like you to be able to right-click on the method and have a context menu item in accordance with "Copy Documentation to the Clipboard".

Do such tools exist?

+4
source share
3 answers

No need to collapse by yourself, see cr-documentor .

CR_Documentor is a DXCore plugin that allows you to see how the documentation will look when it is displayed - in a tool window inside Visual Studio.

This works very well, but I suspect that it works with Resharper a little shaky, so I turned it off until I use it.

+3
source

I just wrote a tool that does this. These are just a few lines of code, and it is not finished yet, but it is very simple to expand (I could do it somewhere tomorrow).

Result: just press β€œextract” from the menu and the result will be on the clipboard .

alt text

Two very simple steps:

  • Write a program that takes a file as an argument, takes some text from this file, and pastes them into the clipboard.
  • Integrate this program into your IDE.

STEP 1, part 1 The main program, take the file, send it to the "extractor" and write the results to the clipboard.

class Program { [STAThread] static void Main(string[] args) { if (args.Length == 0) return; FileInfo f = new FileInfo(args[0]); Extracter e = new Extracter(f.OpenText().ReadToEnd()); Clipboard.SetText(e.GetExtractedText()); } } 

STEP 1, part 2 Extractor: get all the text elements you need using the regular expression and return the corresponding line. I missed the comments for mail density, and since the principle is simple and explained already.

 public class Extracter { private Regex re; // extend/adapt regex patterns for better result. const String RE_COMMENT_AND_NEXT_LINE= @"(?<=([\/]{3})).+"; public string FileText { get; set; } public Extracter(String FileText) { this.FileText = FileText; } public String GetExtractedText() { StringBuilder sb = new StringBuilder(String.Empty); re = new Regex(RE_COMMENT_AND_NEXT_LINE); foreach (Match match in re.Matches(FileText)) { sb.Append(match.ToString()); } return sb.ToString(); } } 

STEP 2: Add to the IDE

Of course, the IDE is dependent, but always easy. See my screenshot for VS2008:

alt text

+6
source

comment forms .cs files are automatically sent to the xml file. Following are the instructions:

  • Open project properties -> Build
  • below, there is a section "Exit"
  • Select the XML Documentation File check box, and set the output path for this file.
  • This file will have all the documentation for your code copied with it when you created the code.

Once you get all the comments from your project, you can use it the way you want.

http://msdn.microsoft.com/en-us/magazine/cc302121.aspx

Recommendation:

you can disable it during daily work, as if the project size has been increased, it will take time during assembly to generate this file, since it needs to match all the comments. Just run when you release the code to get all the documentation.

+2
source

All Articles