119

I was wondering if there is a way (hopefully keyboard shortcut) to create auto generate function headers in visual studio.

Example:

Private Function Foo(ByVal param1 As String, ByVal param2 As Integer) 

And it would automagically become something like this...


'---------------------------------- 'Pre: 'Post: 'Author: 'Date: 'Param1 (String): 'Param2 (Integer): 'Summary: Private Function Foo(ByVal param1 As String, ByVal param2 As Integer) 
2
  • 1
    If you've landed on this page because this feature seems to be broken in your IDE you should ensure that your code compiles and try again. This feature doesn't work when your code has parsing errors. Commented Jan 6, 2017 at 22:49
  • How to generate todo list in xamarin? Commented Mar 28, 2018 at 11:13

8 Answers 8

201

Make that "three single comment-markers"

In C# it's ///

which as default spits out:

/// <summary> /// /// </summary> /// <returns></returns> 

Here's some tips on editing VS templates.

Sign up to request clarification or add additional context in comments.

9 Comments

And in VB.NET it's triple single quotes (as mentioned in other answer)
That's pretty neat, didn't know about that
The "Generate XML documentation comments for ///" will not work if the previous non white space line starts with "///"
Is it possible to do this automatically on every method, property and variable? Even if the code already exists?
tips link fixed again. curse you, one-way web!
|
52

GhostDoc!

Right-click on the function, select "Document this" and

private bool FindTheFoo(int numberOfFoos) 

becomes

/// <summary> /// Finds the foo. /// </summary> /// <param name="numberOfFoos">The number of foos.</param> /// <returns></returns> private bool FindTheFoo(int numberOfFoos) 

(yes, it is all autogenerated).

It has support for C#, VB.NET and C/C++. It is per default mapped to Ctrl+Shift+D.

Remember: you should add information beyond the method signature to the documentation. Don't just stop with the autogenerated documentation. The value of a tool like this is that it automatically generates the documentation that can be extracted from the method signature, so any information you add should be new information.

That being said, I personally prefer when methods are totally selfdocumenting, but sometimes you will have coding-standards that mandate outside documentation, and then a tool like this will save you a lot of braindead typing.

4 Comments

And this is exactly the kind of 'documentation' that I detest. It just adds bytes without telling me anything the method and parameter names don't tell me already. Do not do this, without editing the comment into some worth-while... :-(
Of course you should be editing it to add information. But as a template it is very nice.
@Rasmus: It's a template that, for good documentation, should be thrown away completely and rewritten anyway, since it has no informational content. So it's actually more effort than if it were just blank.
it not working on VISUAL STUDIO 2022
43
/// 

is the shortcut for getting the Method Description comment block. But make sure you have written the function name and signature before adding it. First write the Function name and signature.

Then above the function name just type ///

and you will get it automatically

enter image description here

3 Comments

nice unusual feature-of-a-post, your animation.
How did you do that? I like that answer. Never seen this before.
its nice. one addition would be parameters to the function.
21

Visual Assist has a nice solution too, and is highly customizable.

After tweaking it to generate doxygen-style comments, these two clicks would produce -

/** * Method: FindTheFoo * FullName: FindTheFoo * Access: private * Qualifier: * @param int numberOfFoos * @return bool */ private bool FindTheFoo(int numberOfFoos) { } 

(Under default settings, its a bit different.)


Edit: The way to customize the 'document method' text is under VassistX->Visual Assist Options->Suggestions, select 'Edit VA Snippets', Language: C++, Type: Refactoring, then go to 'Document Method' and customize. The above example is generated by:

va_doxy

To Insert The Snippet: with cursor in method name/signature, alt+shift+q > "document method"

3 Comments

Please share how you set this up in VA
Elaborated at the answer. Hope this helps.
To Insert The Snippet: with cursor in method name/signature, alt+shift+q > "document method"
16

Normally, Visual Studio creates it automatically if you add three single comment-markers above the thing you like to comment (method, class).

In C# this would be ///.

If Visual Studio doesn't do this, you can enable it in

Options->Text Editor->C#->Advanced

and check

Generate XML documentation comments for ///

pictured description

Comments

6

In visual basic, if you create your function/sub first, then on the line above it, you type ' three times, it will auto-generate the relevant xml for documentation. This also shows up when you mouseover in intellisense, and when you are making use of the function.

Comments

3

You can use code snippets to insert any lines you want.

Also, if you type three single quotation marks (''') on the line above the function header, it will insert the XML header template that you can then fill out.

These XML comments can be interpreted by documentation software, and they are included in the build output as an assembly.xml file. If you keep that XML file with the DLL and reference that DLL in another project, those comments become available in intellisense.

1 Comment

That's VB.NET: in C# it's ///
-2

I'm working on an open-source project called Todoc which analyzes words to produce proper documentation output automatically when saving a file. It respects existing comments and is really fast and fluid.

http://todoc.codeplex.com/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.