Resharper结构查找和替换对象

时间:2015-03-08 23:31:57

标签: c# resharper

我使用的库为string.Format提供了自定义的流畅实现。我们的想法是用一个更自然的方式替换常见格式构造:

// From this
string.Format("some format string with {0} parameter", 1);
string.Format(SomeConstant, "abc");
// To this
"some format string with {0} parameter".Format(1);
SomeConstant.Format("abc");

我试图在Resharper中设置一个简单的结构查找和替换模式,以帮助我处理代码库中的那些。我注意到如果我将格式字符串参数设置为参数占位符只匹配一个参数并且参数列表使用实体对象(如Person对象),前面的示例将变为:

// Note that this is the System.String class and not the original format string
String.Format(someEntity);

如果实体首次转换为字符串,则它会正确匹配并保持格式字符串,如我所料。

SomeConstant.Format(someEntity.ToString());

我必须使用表达式类型为System.String Expression占位符来正确匹配第一个参数。

这是一个错误还是我在这种行为中没有理解的东西?为什么第二个参数的类型会影响第一个参数的匹配?我有一种感觉,我可能会误解 Argument Placeholders 是如何工作的......

注意:使用Resharper 9.0 Update 1

编辑:根据要求,这是搜索模式的详细信息:

搜索模式:String.Format($format$, $args$)
替换模式:$format$.Format($args)
格式:Argument Placeholder, matching exactly one argument
args:Argument Placeholder, matching at least one argument

0 个答案:

没有答案