Skip to main content

Declare Method

Generates a method for the selected method call with appropriate parameters. Activates Text Fields for the method parameters and drops a marker onto the initial method call.

#Purpose

This refactoring is especially useful for those practicing Test-Driven Development. It allows you to first write a code fragment and then easily create declarations for methods referenced in it.

#Availability

Available from the context menu or via shortcuts:

  • when the caret is on a statement calling an undeclared method. The caret should be on the method name.

#Example

class TestClass
{
    private void TestMethod()
    {
        int a = 15;
        string str = "Test";Mymethod(a, str);
    }
}
Class TestClass
    Private Sub TestMethod()
        Dim a As Integer = 15
        Dim str As String = "Test"MyMethod(a, str)
    End Sub
End Class

Result

class TestClass
{
    private void Mymethod(int a, string str)
    {
        throw new NotImplementedException();
    }
    private void TestMethod()
    {
        int a = 15;
        string str = "Test";
        Mymethod(a, str);
    }
}
Class TestClass
    Private Sub MyMethod(ByVal a As Integer, ByVal str As String)
        Throw New NotImplementedException()
    End Sub
    Private Sub TestMethod()
        Dim a As Integer = 15
        Dim str As String = "Test"
        MyMethod(a, str)
    End Sub
End Class

#Animation

rsDeclareMethod