Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate a class from an Interface

Suppose I have a new interface:

public interface IClientRepository 
{
    void Add(Customer customer);
    void Remove(Customer customer);
    Customer Get(long id);
}

Now I'd like to do the following:

  • Create a new class with a good default name (e.g. "ClientRepository");
  • Have that class in a file as a sibling of the interface code file.

I think I've seen instructors of Pluralsight videos do this on numerous occasions, but I can't seem to find out what keyboard shortcuts to use for this.

What have I tried? Well:

  • Google Fu mostly provides a way to do the opposite (extract interface), e.g. posts like this.
  • Read through the Refactorings docs for ReSharper as well as those for Code Generation.
  • Hit CTRL + SHIFT + r on the interface declaration, but none of the options seems to be what I need.

What am I missing here? How do you generate a class from an interface?

like image 767
Jeroen Avatar asked Aug 29 '14 09:08

Jeroen


1 Answers

  1. Put the cursor on the interface type name, for instance here:

     public interface |IClientRepository 
    

    Hit Alt+Enter, and select Create Derived Type. This creates a class called ClientRepository in the same file as IClientRepository.

  2. Now put your cursor on the class type name of ClientRepository, and hit Ctrl+R, Ctrl+O and select Move to another file. It will default to a file name that matches the type name and puts it in the same directory as the file it was moved from.

like image 192
Patrick Quirk Avatar answered Oct 23 '22 19:10

Patrick Quirk