我们的代码库中有很多StringBuilder.AppendFormats,它们的字符串以换行符结尾。我制作了一个名为AppendLineFormat的扩展方法,并希望使用Resharper的“自定义模式”功能来识别和修复那些使用新扩展方法的旧调用(并在将来向其他人推荐这种新扩展方法)。
StringBuilder sb = new StringBuilder();
int i = 1;
sb.AppendFormat("i is {0}\r\n", i);
进入
sb.AppendLineFormat("i is {0}", i);
有没有办法使用正则表达式(带有替换)来识别匹配的字符串?我不想将每个AppendFormat都转换为AppendLineFormat-仅将那些以\ r \ n结尾的字符串转换为AppendLineFormat。这是到目前为止我得到的。
搜索模式:
$sb$.AppendFormat($newLineString$,$args$)
替换图案:
$sb$.AppendLineFormat($newLineString$,$args$)
在哪里
"(.*)\\r\\n"
(完全错误,我知道)不幸的是,目前尚不支持。
有很多问题,您可以投票给他们:
解决方法是使用Visual Studio“查找和替换”功能。
搜索模式:
\.AppendFormat\(\"(.+?)(?>\\r\\n\")
替换模式:
.AppendLineFormat("$1"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句