1

I'm creating an interface on a 3rd party DLL so that I can use it over WCF. The implementation looks like this:

public class MyImplementation : IMyInterfaceFor3rdPartyClass
{
  public ThirdPartyClass TPC = new ThirdPartyClass();

  int MethodA()
  {
    return TPC.MethodA();
  }

  int MethodB(int someParameter)
  {
    return TPC.MethodB(someParameter);
  }
}

However, there are about 50 methods and I really don't feel like implementing every one. Is there an easier way than hand typing the entire thing? Am I going about this the wrong way? I've already had VS "auto implement" all the method names which generates the method names and throw new NotImplementedException();.

Edit Just had a thought: can the 3rd party class somehow implement the interface?

MikeH
  • 4,242
  • 1
  • 17
  • 32
  • This is the kind of stuff I think ReSharper can do https://www.jetbrains.com/resharper/features/code_generation.html – Eric Nov 11 '14 at 00:14
  • ... and [this old answer](http://stackoverflow.com/a/17422998/243245) says ReSharper calls this ['delegating members'](https://www.jetbrains.com/resharper/webhelp/Code_Generation__Delegating_Members.html). (I'd have called it 'Facade'.) – Rup Nov 11 '14 at 00:16
  • That looks promising. – MikeH Nov 11 '14 at 00:17
  • About your Edit - Doesn't `ThirdPartyClass` already implement the interface? from sample code above, it "looks" like it does.. but then, it might not.. – Vikas Gupta Nov 11 '14 at 00:19
  • this may or may not help as well http://stackoverflow.com/questions/5042605/how-can-subclasses-share-behavior-when-one-already-derives-from-a-different-base – MethodMan Nov 11 '14 at 00:19
  • @VikasGupta The interface was derived from the class, but since I derived it, it doesn't *explicitly* implement the interface. Is there someway to do that? – MikeH Nov 11 '14 at 00:22
  • Does your interface has all public methods with same declaration as in the third party class? – danish Nov 11 '14 at 00:28
  • @danish Yes, it matches exactly – MikeH Nov 11 '14 at 00:29
  • Update method stub snippet here: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC#\Snippets\1033\Refactoring. You can try to ensure that whenever the interface is implemented, method body will look like TPC.. I cannot figure out what the syntax is to do this in snippets. – danish Nov 11 '14 at 02:18

0 Answers0