Reputation: 9821
I like to add annotations like StringFormatMethod
to my formatting methods, so ReSharper highlights format parameters etc.
ReSharper also has syntax highlighting for regular expressions, and I would like the same treatment of regex patterns in my own extension method ReplaceRegex
:
Notice how the \s*
is highlighted only in Regex.Replace
.
I looked in the Jetbrains.Annotations
namespace, but could not find any relevant attributes. Is there currently no way to do this?
Upvotes: 4
Views: 1151
Reputation: 9821
Turns out the problem was I had an old version of Jetbrains.Annotations
.
The attribute I was looking for was RegexPatternAttribute
, found in JetBrains.Annotations.
Here is my extension method with the attribute:
public static string ReplaceRegex(this string str, [RegexPattern] string pattern, string replacement, RegexOptions options = RegexOptions.None) {
return Regex.Replace(str, pattern, replacement, options);
}
Now I get the fancy coloring for my extension method:
Thanks to @AakashM for the comment with the answer!
Upvotes: 7