问题
ReSharper has a fancy feature that highlights format variables in e.g. string.Format():

Now, I have written an extension to format strings fluently like:
public static string FormatWith(this string me, params object[] args) {
return string.Format(me, args);
}
So I can do:

Now I would like to implement similar syntax highlighting for the {0}
and {1}
whenever a string is followed by .FormatWith
. Is this possible in ReSharper?
回答1:
You can do this by using StringFormatMethodAttribute in JetBrains.Annotations package.
[StringFormatMethod("me")]
public static string FormatWith(this string me, params object[] args) {
return string.Format(me, args);
}
回答2:
It might work with placing annotations on your extension method.
http://www.jetbrains.com/resharper/webhelp/Code_Analysis__Annotations_in_Source_Code.html
There is more elaboration here.
http://www.jetbrains.com/resharper/webhelp/Code_Analysis__String_Formatting_Methods.html
来源:https://stackoverflow.com/questions/16939627/in-resharper-7-is-it-possible-to-extend-syntax-highlighting-of-strings