Jeroen
Jeroen

Reputation: 63870

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:

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:

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

Upvotes: 6

Views: 2116

Answers (3)

Patrick Quirk
Patrick Quirk

Reputation: 23767

  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.

Upvotes: 10

Andrej Adamenko
Andrej Adamenko

Reputation: 1668

I think Resharper does not have this possibility. However you can do it semi-manually. Type the following in the same file where

public class ClientRepository : IClientRepository {}

Then use implement members command.

Then use refactor -> move to another file command on the class

Upvotes: 0

MikMik
MikMik

Reputation: 3466

I don't use ReSharper, but I think you have to declare your class as derived from the interface, and then use ReSharper to implement the interface members, as explained here.

You can probably create the new class in the same file as the interface, and then use some "move" refactoring to create the corresponding files.

Upvotes: 0

Related Questions