title: How to automatically Proxy a DLL(managed) through another DLL(managed)?
body: <p>I have a strange request, </p>
  
  <p>Actually our solution is this: </p>
  
  <ul>
  <li>APP.EXE -> MYDLL.DLL</li>
  </ul>
  
  <p><code>APP.EXE</code> consumes <code>MYDLL</code> assembly methods.</p>
  
  <p>Now the client request to implement this variations: </p>
  
  <ul>
  <li>APP.EXE -> <strong>MYDLL_PROXY.DLL</strong> ->  MYDLL.DLL (load dynamically)</li>
  </ul>
  
  <p>MYDLL_PROXY.DLL must act like a proxy so, calling "MYDLL_PROXY.Method1" would load external MYDLL.DLL and invoke Method1 on it and return the result. </p>
  
  <p>Something like this with reflection: </p>
  
  <pre><code>    //MYDLL_PROXY.dll
          ass = Assembly.LoadFrom(@"C:\mydll.dll");       
          String MyGenericMethod ="Something"
          Type MyType = ass.GetTypes()[0];
          Object o = Activator.CreateInstance(MyType);
          MethodInfo Method = ass.GetTypes()[0].GetMethod(MyGenericMethod);
          return Method.Invoke(null, new object[] { /* parameters go here */ });
  </code></pre>
  
  <p>So, before get mad, there is a quick'n'dirty way to create a fake dll that act like a proxy to another ? </p>
  
  <p><strong>I need to proxy all : Method, properties, events .</strong></p>
  
  <p>Thanks for any help.</p>
  
  <p><strong>NB</strong>: is an old project and must stay with Framework 2.0</p>
  
  <hr>
  
  <p><strong>Update</strong> </p>
  
  <p>If reflections is not the correct way something like this incapsulate can be possible ? And what about the events ? </p>
  
  <p>ExternalDLL:</p>
  
  <pre><code>public class NastyExternalClassInExternalDll
  {
      public void Foo() { ... }
  }
  </code></pre>
  
  <p>MainDLL:</p>
  
  <pre><code>public interface IFooable
  {
      void Foo();
  }
  
  public sealed class NastyExternalClassWrapper : IFooable
  {
      private readonly NastyExternalClassInExternalDll original;
  
      public NastyExternalClassWrapper(NastyExternalClass original)
      {
          this.original = original;
      }
  
      public void Foo()
      {
          original.Foo();
      }
  }
  </code></pre>