我非常喜欢“转换参数”功能
在某些情况下,我想将参数转换为对象初始值设定项而不是构造函数,以避免长参数。
这是示例代码
namespace Test.Test
{
public class TestUtility
{
public void Example()
{
this.GetTest("a1", "a2", "a3", "a4", "a5");
}
public void GetTest(string a1, string a2, string a3, string a4, string a5)
{
Console.WriteLine($"{a1}\t{a2}\t{a3}\t{a4}\t{a5}");
}
}
}
我想要的是:
namespace Test.Test
{
public class TestUtility
{
public void Example()
{
// this is how Resharper generated
// this.GetTest(new TestClass("a1", "a2", "a3", "a4", "a5"));
// what I want
this.GetTest(new TestClass
{
A1 = "a1",
A2 = "a2",
A3 = "a3",
A4 = "a4",
A5 = "a5"
});
}
public void GetTest(TestClass testClass)
{
Console.WriteLine($"{testClass.A1}\t{testClass.A2}\t{testClass.A3}\t{testClass.A4}\t{testClass.A5}");
}
}
}
非常感谢
不幸的是,我无法使用 R# 或 Rider 生成它 - 所以它似乎不受支持。
也许您可以在 JetBrains 创建一个票证,以便他们可以将其作为功能请求进行跟踪。
我非常想要这个,以至于我开发了自己的重构扩展:(
https://marketplace.visualstudio.com/items?itemName=jiri-machacek.ExtractMethodParameters