Export (0) Print
Expand All

How to: Refactor Code with Extract Interface 

Use this procedure to perform the Extract Interface refactoring operation.

To use Extract Interface

  1. Create a console application as described in the example below.

    For more information, see Console Application.

  2. With the cursor positioned in MethodB, select Extract Interface on the Refactor menu. The Extract Interface Dialog Box appears.

    You can also type the keyboard shortcut CTRL+R, CTRL+I to display the Extract Interface Dialog Box.

    You can also right-click the cursor, point to Refactor on the context menu, and then click Extract Interface to display the Extract Interface Dialog Box.

  3. Click Select All.

  4. Click the OK button.

    You see the new file, IProtoA.cs, and the following code:

    using System;
    namespace TopThreeRefactorings
    {
        interface IProtoA
        {
            void MethodB(string s);
        }
    }
    

Example

To set up this example, create a console application named ExtractInterface, and then replace Class1 with the following code. For more information, see Console Application.

    // Invoke Extract Interface on ProtoA.
    // Note:  the extracted interface will be created in a new file.
    class ProtoA
    {
        public void MethodB(string s) { }
    }

See Also

Community Additions

ADD
Show:
© 2014 Microsoft