Is there a way to remove a parameter from all calls to a method in Visual Studio 2022?

73 Views Asked by At

Developing a ZWCad API using .NET and C#, Visual Studio.

I have started with this class constructor.

internal class Foo
{
    public List<Bar> BarFromThisFoo { get; set; }

    public double MaxYBar { get; set; } = 0;
    
    // Some other properties

    public Foo(bool autoGetBar)
    {
        if(autoGetBar)
        {
            BarFromThisFoo = GetBarFromThisFoo();
        }       

        // Get some other properties
    }
}

Now, I'm overloading the constructor and one of the methods to the following:

internal class Foo
{
    public List<Bar> BarFromThisFoo { get; set; }

    public double MaxYBar { get; set; } = 0;
    
    // Some other properties

    public Foo()
    {
         BarFromThisFoo = GetBarFromThisFoo();

        // Get some other properties
    }

    public Foo(ObjectId[] selectedObjets)
    {
         BarFromThisFoo = GetBarFromThisFoo(selectedObjets);

        // Get some other properties
    }

}

The problem is that I have 12 calls to this method and naturally getting errors in all off them since I don't have anymore the bool parameter in the constructor. And all the refactoring options that I have from visual studio point me to add the bool parameter the constructor, which I don't want.

Is there some refactoring option or tool to this situations?

For now I'm using the Find and Replace tool, but it is kind of slow when having multiple files.

I also have looked for Visual Studio extensions but haven't tried none since none of them seems to cover this situation.

1

There are 1 best solutions below

0
shingo On BEST ANSWER

Official document can be found here: Change a method signature refactoring

  1. Right click on the method, choose the Quick Actions menu. Don't use Ctrl+., otherwise you may not see the second menu item. (but Alt+Enter works, maybe it's a bug)

    Step1

  2. Choose the Change signature menu.

    Step2

  3. In the dialog, you can click the Remove button to remove parameters.

    Step3

  4. If you need to add a new parameter, click the Add button, in the new dialog, you can specify the parameter type, name, and the value passed by at the call sites.

    Step4