1

I've noticed Ghostdoc never seems to attempt to produce returns documentation. Given a method like this:

/// <summary>
/// Gets the departure date.
/// </summary>
/// <returns></returns>
private DateTime GetDepartureDate()
{
    // TODO:
}

I'd expect it to populate the returns information like so:

/// <summary>
/// Gets the departure date.
/// </summary>
/// <returns>The departure date.</returns>
private DateTime GetDepartureDate()
{
    // TODO:
}

I've seen this but this is quite old and to be honest, I don't really understand it. Any ideas?

Clearly it will never be perfect but anything is better than nothing.

Robbie Dee
  • 1,939
  • 16
  • 43

1 Answers1

1

By default, Ghostdoc does not attempt to provide any text for return types. However, you can set up a rule to do it, as suggested in the link in the question.

For example, to set a rule that adds a return description to any method with a name starting 'Get...' and using the rest of the method name for the text (as suggested in the question):

  1. In Visual Studio, go to Tools > Ghostdoc > Options
  2. Select Rules under GhostDoc in the tree
  3. Select the Methods 'folder' in the right-hand Rules list (you may need to scroll the list)

Add a new rule to match methods starting with 'Get...':

  1. Click Add... and OK to add a new 'Custom match' rule
  2. Change the name to something like:

    Match 'Get' methods

  3. Click the <any> link after method name to set the condition
  4. Select starts with, type

    Get

    followed by a space, in the text box and click OK

Now, to set the 'returns' template text:

  1. In the grid, click the ellipsis button ... next to <returns>
  2. Type

    The

    followed by a space, in the 'Template text' box

  3. Expand MethodName > Words, select ExceptFirst, click Insert and OK

The default summary text is overridden by the new rule, so to add something sensible for our new rule:

  1. Back in the grid, click the ... button next to <summary>
  2. Type

    Gets the

    followed by a space, in the Template text box

  3. Expand MethodName > Words, select ExceptFirst, click Insert and OK
  4. Click OK to complete the setting up of the rule

Ensure the rule is positioned below the existing int GetHashCode() rule so that the latter one will take precedence in that special case. Click OK to close the Options dialog and you're ready to try out the new rule.

Ian
  • 1,221
  • 1
  • 18
  • 30