In ReSharper 7, is it possible to extend syntax highlighting of strings?

╄→尐↘猪︶ㄣ 提交于 2019-12-23 19:45:34

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!