Visual Studio加载项,用于验证string.Format方法

HuB*_*eZa 9 c# vsx string-formatting visual-studio

string.Format是一种非常危险的方法.有很多东西可能出错,没有任何编译错误:

string.Format("{0{", text);
string.Format("{1}", text);
string.Format("(0)", text);
string.Format("{0}", text1, text2);
Run Code Online (Sandbox Code Playgroud)

我正在寻找一种在编译时找到这个问题的方法.如果我没记错的话,Resharper发现了一些错误,但它对我的血液来说太丰富了.

Skl*_*vvz 2

Resharper会为您做到这一点 - 即使在编辑时:-)。

但请注意,诸如此类的事情

String.Format("{0} blabla", foo, bar);
Run Code Online (Sandbox Code Playgroud)

不要生成错误(毕竟,决定隐藏一个值是完全可以的)。