How to remove all C# methods/properties/fields “su

2020-05-19 02:09发布

问题:

How to remove all C# methods/properties/fields "summary" comments

(starting with ///)

in current document in Visual Studio with one shot?

In other words convert this:

/// <summary>
/// Very stupid comment generated with very stupid tool
/// </summary>
protected void MyMethod
{

}

Into this:

protected void MyMethod
{

}

回答1:

How about

  • Ctrl+H for quick replace
  • Mark Use : Regular expressions
  • Enter in Find what field following expression ^.*\/\/\/.*$\n (shortly - line with /// pattern)
  • Leave Replace with field empty
  • Make sure that you Look in in Current Document
  • Click Replace All


回答2:

Regex pattern ^.*\/\/\/ ?<summary>.*\n(?:^.*\/\/\/.*$\n)* will be more suitable in this case because it will match whole summary comment at once.

  • ^.*\/\/\/ ?<summary>.*\n - matches line with /// <summary> text (with optional space after slashes)
  • (?:)+ - non-capturing group, repeated zero or more times
  • ^ - beginning of the line
  • .* - any characters
  • \/\/\/ - three slashes
  • .* - any characters
  • $ - end of line
  • \n - line break symbol