Can you add custom refactorings ?

I'm finding that I have to implement the following pattern frequently

interface ISomeInterface
{

     int SomeMethod();
     int AnotherMethod();


}

public class MySomeImplementation : ISomeInterface
{
     private ISomeInterface existing;

     public MySomeImplementation( ISomeInterface existing )
     {
          this.existing = existing;
     }

     public int SomeMetthod()
     {
          return this.existing.SomeMethod();
     }

     public int AnotherMethod()
     {
          return this.existing.AnotherMethod();
     }
}

Sometimes the interface is an abstract baseclass and then it's override and delegate.  

A good example of this the IWebDriver and IWebElement interfaces from the Selenium system.

Can I create a refactor to create a class that implements the same interface and delegate all interface calls to an existing implementation.  Similiar in concept to wrapping a property around a field.
2 comments
Comment actions Permalink

Hello Robert
     You can achieve similar behavior by using ReSharper | Edit | Generate Code | Delegating members inside such class:

public class MySomeImplementation : ISomeInterface
{
     private ISomeInterface existing;

     public MySomeImplementation( ISomeInterface existing )
     {
          this.existing = existing;
     }
}

     however, you will need to manually create such class first. You can automate this process further by creating a custom ReSharper plug-in.

     Thank you!

Andrey Serebryansky

Software Developer

JetBrains, Inc

http://www.jetbrains.com

"Develop with pleasure!"

0
Comment actions Permalink

Thanks Andrey... i'll look at the SDK and have a go.

Cheers...

0

Please sign in to leave a comment.