Essential refactoring tools and quality-of-life improvements for C# developers in VS Code.
- Extract interfaces from C# classes
- Automatically generate the interface in the same directory as the class
- Update the class to implement the newly created interface
- Option to provide a custom name and path for the interface
- Add a public method from a class to an interface it implements
- Automatically finds interface files in the workspace
- Supports multiple interfaces (prompts for selection)
- Prevents duplicate method signatures
- Add a public property from a class to an interface it implements
- Supports all property types including generics and nullable types
- Automatically finds interface files in the workspace
- Prevents duplicate property signatures
- Generate stub implementations for all interface members
- Automatically detects unimplemented methods, properties, and events
- Generates proper method stubs with
throw new NotImplementedException() - Supports multiple interfaces (select which one to implement)
- Open a C# file in VS Code.
- Press
Ctrl + .on aclasskeyword (place the cursor on it). - In the context menu, select "Extract Interface".
- Enter a name for the new interface (default is
Ifollowed by the class name). - The extension will:
- Generate an interface with all public methods of the class.
- Create the interface in the same directory as the class.
- Modify the class to implement the new interface.
Given a class like this:
public class DiceManager
{
public void RollDice() { }
public int GetScore() { return 0; }
}After clicking on "Extract Interface", it will generate the following interface:
public interface IDiceManager
{
void RollDice();
int GetScore();
}The DiceManager class will be updated to:
public class DiceManager : IDiceManager
{
public void RollDice() { }
public int GetScore() { return 0; }
}- Open a C# file that implements an interface.
- Press
Ctrl + .on a public method. - Select "Add 'MethodName' to Interface".
- If the class implements multiple interfaces, select which one to add the method to.
- The method signature will be added to the interface file.
- Open a C# file that implements an interface.
- Press
Ctrl + .on a public property. - Select "Add 'PropertyName' to Interface".
- If the class implements multiple interfaces, select which one to add the property to.
- The property signature will be added to the interface file.
- Open a C# class that declares it implements an interface (e.g.,
public class MyClass : IMyInterface). - Press
Ctrl + .on the class declaration. - Select "Implement 'InterfaceName'".
- If the class implements multiple interfaces, each will be shown as a separate option.
- The extension will generate stubs for all unimplemented members.
Given an interface:
public interface IDataService
{
int Id { get; set; }
event EventHandler DataChanged;
Task<string> GetDataAsync(int id);
}And a class that doesn't implement it yet:
public class DataService : IDataService
{
}After clicking on "Implement 'IDataService'", the class will be updated to:
public class DataService : IDataService
{
public int Id { get; set; }
public event EventHandler DataChanged;
public Task<string> GetDataAsync(int id)
{
throw new NotImplementedException();
}
}Make sure you're pressing Ctrl + . on the class declaration (public class <ClassName>) in the editor. If you are on a method or variable, the option won't appear.
If Ctrl + . doesn't work, try right-clicking on the class declaration and selecting "Extract Interface" from the context menu.
Ensure that the class is being correctly identified by the extension. If the class is not in the format public class <ClassName>, or if it's in a file that doesn't follow standard C# conventions, the extension may not function as expected.