How to Transform Parameters to Object Initializer

Dear JetBrains Developer:

I like the feature "Transform Parameters" very much.

In some cases, I would like to transform parameters to object initializer instead of constructors because of avoiding long parameters.

This is the example code

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}");
        }
    }
}

and what I want is:

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}");
        }
    }
}

Thank you very much

1 comment
Comment actions Permalink

Hello Eric Ping, thank you for your question. As far as I know, there is no such functionality yet. The following issue describes functionality similar to the one you described. Please comment or vote for it to get notifications about status changes. Thank you!

0

Please sign in to leave a comment.