Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Resharper结构查找并替换为对象_C#_Resharper - Fatal编程技术网

C# Resharper结构查找并替换为对象

C# Resharper结构查找并替换为对象,c#,resharper,C#,Resharper,我使用一个库,它为string.Format提供了一个自定义的fluent实现。我们的想法是用一种更自然的方式来代替通用格式结构,如下所示: // 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); SomeConst

我使用一个库,它为
string.Format
提供了一个自定义的fluent实现。我们的想法是用一种更自然的方式来代替通用格式结构,如下所示:

// 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中设置一个简单的结构查找和替换模式,以帮助我处理代码库中的问题。我注意到,如果我将format string参数设置为正好匹配一个参数的参数占位符,并且参数列表使用实体对象(如Person对象),那么前面的示例将变成:

// Note that this is the System.String class and not the original format string
String.Format(someEntity);
如果首先将实体转换为字符串,那么它将正确匹配,并保持我所期望的格式字符串

SomeConstant.Format(someEntity.ToString());
我必须使用表达式占位符,其表达式类型为
System.String
,以正确匹配第一个参数

这是一个bug还是在这个行为中有我不理解的东西?为什么第二个参数的类型会影响第一个参数的匹配?我有一种感觉,我可能误解了参数占位符是如何工作的

注意:使用Resharper 9.0更新1

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

搜索模式:
String.Format($Format$,$args$)

替换模式:
$format$.format($args)

格式:
参数占位符,正好匹配一个参数


args:
参数占位符,至少匹配一个参数

,我认为您需要展开您的问题。如果看不到搜索或替换模式,也不知道占位符是什么,就很难判断它是否正常工作。