45

From Eclipse I'm used that when I start typing a comment for a class or method, the parameters, return types and exceptions are autogenerated. But in VisualStudio 2010 I can't find something like this. Any hints how to achieve that?

RoflcoptrException
  • 51,941
  • 35
  • 152
  • 200
  • 4
    Note that, in C#, "exceptions" are typically not commented, since they aren't defined at the method level like in Java... – Reed Copsey Mar 14 '11 at 16:22

5 Answers5

112

The only way I know to do this is on the line right above your method just type "///" and it will generate a comment template based on the method.

AridTag
  • 1,284
  • 1
  • 11
  • 13
  • 3
    That'll teach me for writing my comments before I write the method, so that I am focussed on what I intend the method to do! – Peter M Mar 14 '11 at 17:15
  • 3
    But that does not include Exceptions. Would be very nice if it could create a summary of all exceptions and we could delete the ones that we catch. By specifying them manually I often forget to comment some of them wich is awful, especially in libraries used by other people. – Noel Widmer Mar 17 '15 at 08:50
  • Used to be: 3 forward-slashes then a TAB. Doesn't seem to work VisualStudio.17.Release/17.7.1+34009.444. – tim Aug 21 '23 at 14:37
14

GhostDoc is a free extension that will do this. Just hit (by default) Ctrl+D anywhere within a method, and it will add XML Documentation comments with defaults filled in (though they typically should be modified/expanded).

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
10

Use "///" instead of "//" for comments. For example, the following comment was auto-generated by just starting to type "///":

/// <summary>
/// </summary>
/// <param name="terms"></param>
public TVec(IEnumerable<Term> terms)
{
}
Alex Shtoff
  • 2,520
  • 1
  • 25
  • 53
3

Try typing "///" one line ahead of a method. Tell me if that is what you are looking for.

Reza M.
  • 1,205
  • 14
  • 33
1

You can use Ghostddoc to generate alot of your xml comments: http://submain.com/products/ghostdoc.aspx

I think there is a free version available.

James Woolfenden
  • 6,498
  • 33
  • 53