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.
Official document can be found here: Change a method signature refactoring
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)
Choose the Change signature menu.
In the dialog, you can click the Remove button to remove parameters.
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.