我们的代码库有很多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结尾的那些。这是我到目前为止所做的。
搜索模式:
$sb$.AppendFormat($newLineString$,$args$)
替换模式:
$sb$.AppendLineFormat($newLineString$,$args$)
其中
"(.*)\\r\\n"
的标识符(完全错误,我知道)答案 0 :(得分:2)
不幸的是,目前它不受支持。
有很多问题,你可以投票给他们:
作为一种解决方法,您可以使用Visual Studio查找和替换功能。
搜索模式:
\.AppendFormat\(\"(.+?)(?>\\r\\n\")
替换模式:
.AppendLineFormat("$1"