title: Intercept only interface methods with DynamicProxy
body: <p>I got an interface like this</p>
  
  <pre><code>public interface IService
  {
      void InterceptedMethod();
  }
  </code></pre>
  
  <p>A class that implements that interface and also has another method</p>
  
  <pre><code>public class Service : IService
  {
      public virtual void InterceptedMethod()
      {
          Console.WriteLine("InterceptedMethod");
      }
  
      public virtual void SomeMethod()
      {
          Console.WriteLine("SomeMethod");
      }
  }
  </code></pre>
  
  <p>And an Interceptor</p>
  
  <pre><code>public class MyInterceptor : IInterceptor
  {
      public void Intercept(IInvocation invocation)
      {
          Console.WriteLine("Intercepting");
          invocation.Proceed();
      }
  }
  </code></pre>
  
  <p>I want to intercept only the methods on Service that exists on IService (i.e I want to intercept InterceptedMethod() but not SomeMethod()), but I don't want to use ShouldInterceptMethod from IProxyGenerationHook.</p>
  
  <p>I can do like this, but since its return an Interface, I can't call SomeMethod on this object</p>
  
  <pre><code>var generator = new ProxyGenerator();
  var proxy = generator.CreateInterfaceProxyWithTargetInterface&lt;IService&gt;(new Service(), new MyInterceptor());
  proxy.InterceptedMethod(); // works
  proxy.SomeMethod(); // Compile error, proxy is an IService
  </code></pre>
  
  <p>One thing that can work is removing the <em>virtual</em> from SomeMethod() and do like this</p>
  
  <pre><code>var proxy = generator.CreateClassProxy&lt;Service&gt;(new MyInterceptor());
  </code></pre>
  
  <p>But I don't like this solution.</p>
  
  <p>I dont like using ShouldInterceptMethod from IProxyGenerationHook, because everytime that I change the interface I also need to change ShouldInterceptMethod, also someone someday can refactor the method name and the method is not intercepted anymore.</p>
  
  <p>There's any other way to do this?</p>