ReSharper Web Help

The Change Signature refactoring combines several different modifications that can be made to the signatures of methods, constructors, properties, and indexers. It performs the following modifications:

Method
  • Change name and return type.
  • Change parameter names and types.
  • Add and remove parameters.
  • Reorder parameters.
Property
  • Change name and return type.
Constructor
  • Change parameter names and types.
  • Add and remove parameters.
  • Reorder parameters.
Indexer
  • Change name.
  • Change parameter names and types.
  • Add and remove parameters.
  • Reorder parameters.

Along with changing the signature itself, ReSharper searches for all usages of the method, property, constructor, or indexer and alters all calls, implementations and overrides that can be safely modified to reflect the change.

 Warning

Changing a return type or a parameter type may cause errors, which you will need to correct manually in the code.

This refactoring is also applicable to type constructors and indexers (though you can't change their names or return types).

To change a signature
  1. Select the method, property, constructor, or indexer in File Structure, or put the caret upon its name in the editor.
  2. In the ReSharper menu or context menu, choose Refactor | Change Signature, or press Ctrl+F6.
  3. If the selected method overrides or implements some other methods, ReSharper suggests to modify the base methods. Click Yes if you want to change the base methods. Click No if you want to change only the selected method without modifying base methods.
  4. The Change Signature dialog box opens.
    Change Signature
  5. In the Name and Return type text boxes, specify new values if necessary.
  6. In the Parameters area, edit types, names, modifiers and default values of the existing parameters. Use Add and Remove buttons to create new and delete existing parameters. Reorder parameters using Move Up and Move Down buttons.
  7. In the Calls area, specify whether you need to change existing method calls:
    • If you want to modify existing method calls, select Modify. For example, if you add a new parameter with the default value "1", refactoring is applied as shown in table 1 below.
    • If you don't want to change the existing method calls, you can override the method and delegate calls. In this case, select Delegate via overloading method.
      For example, if you add a new parameter with the default value "1", the refactoring is applied as shown in table 2 below.
  8. Check the result in the Signature preview text box, and click Continue. If no conflicts are discovered, the changes apply immediately.

 Note

If you changed some parameter type or a return type to a type not used in the current namespace or to a type that can be resolved ambiguously, ReSharper suggests that you specify the desired type and its full name.
Table 1. Modifying existing method calls
Before:
public class SampleClass
{
    public void Foo(int a)
    {
        ...
    }

    public void CallFoo()
    {
        Foo(0);
    }
}
After:
public class SampleClass
{
    public void Foo(int a, int b)
    {
        ...
    }

    public void CallFoo()
    {
        Foo(0,1);
    }
}
Table 2. Leaving existing method calls intact
Before:
 public class SampleClass
 {
    public void Foo(int a)
    {
        ...
    }

    public void CallFoo()
    {
        Foo(0);
    }
 }
After:
public class SampleClass
{
    public void Foo(int a)
    {
        Foo(a, 1);
    }

    public void Foo(int a, int b)
    {
        ...
    }

    public void CallFoo()
    {
        Foo(0);
    }
}