46

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?

1
  • 4
    Note that, in C#, "exceptions" are typically not commented, since they aren't defined at the method level like in Java... Mar 14, 2011 at 16:22

5 Answers 5

114

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.

3
  • 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, 2011 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. Mar 17, 2015 at 8: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, 2023 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).

2
  • 3
    Just want to note: Free for personal use only. In case you care ;-)
    – schoetbi
    Feb 12, 2015 at 10:01
  • 2
    Isn't Free anymore its now Nagware
    – David
    Jun 12, 2019 at 10:31
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)
{
}
1
  • 2
    ''' for anyone wanting to do this in visual basic :) Oct 31, 2016 at 9:35
3

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.