How to add parameters in the comments of a method in Visual Studio after it has been generated?

272 views Asked by At

I have comments such as:

/// <summary>
///     Creates a filename given the end date provided
/// </summary
/// <returns></returns>
public static string GetFileName(DateTime date, string filePath) {
        var ret = string.Format("file_{0}[{1}].txt", date.ToString("yyyyMMdd"), date.ToString("HHmm"));
        return Path.Combine(filePath, ret);
    }

Visual studio automatically created the comments above when I typed ///.

Is there away to re-generate the above comments and add in the Parameters, which I've newly added recently?

I know I can delete and redo it by typing /// and it will automatically generate with the proper parameters. Is there a a different way?

4

There are 4 answers

0
TheMi7ch On

GhostDoc is a Visual Studio extension that could help out with generating these types of documentation.

I've also heard good things about Resharper, but haven't personally used it.

Otherwise, I usually just retype the /// if it ever changes.

1
Yeldar Kurmangaliyev On

First, you can do it manually by adding necessary <param> items to your summary.

/// <summary>
///     Creates a filename given the end date provided
/// </summary>
/// <param name="date">It is a date</param>
/// <param name="filePath">Valid path</param>
/// <returns></returns>
public static string GetFileName(DateTime date, string filePath) {
   var ret = string.Format("file_{0}[{1}].txt", date.ToString("yyyyMMdd"), date.ToString("HHmm"));
    return Path.Combine(filePath, ret);
}

Second (for lazy people), you can remove this comment and type "///" again :)

0
Yogi On

GhostDoc is the tool to go for as also suggested by TheMi7ch. You can download it using Visual Studio Extension and Updates under Tools menu.

0
The Vermilion Wizard On

Intellisense works pretty well for me:

  1. Go to the end of the </summary> line and hit enter - VS will generate a new line with /// on it already.
  2. Type <p and Intellisense should give you some pretty good suggestions.

On some setups I've seen Intellisense simply list all the missing param tags, and you can just add them one by one this way. On other setups it will only give you <param name=""></param> and place the insertion point between the quotes for you fill in the parameter name. I'm guessing which behavior you get depends on whether you have Resharper installed.