Geir Sagberg
Geir Sagberg

Reputation: 9821

Is there a ReSharper annotation for regex highlighting?

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:

Regular expresssions syntax highlighting

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

Answers (1)

Geir Sagberg
Geir Sagberg

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: Regex syntax highlighting

Thanks to @AakashM for the comment with the answer!

Upvotes: 7

Related Questions