title: Castle DynamicProxy2: Get the Target inside an Interceptor?
body: <p>I'm using Castle DynamicProxy2 to "tack on" interfaces to retrieve fields from a dictionary.  For example, given the following class:</p>
  
  <pre><code>public class DataContainer : IDataContainer
  {
      private Dictionary&lt;string, object&gt; _Fields = null;
  
      public Dictionary&lt;string, object&gt; Data
      {
          get { return _Fields ?? (_Fields = new Dictionary&lt;string, object&gt;()); }
      }
  }
  </code></pre>
  
  <p>I want to use the following interface as an interface proxy to extract the "Name" value out of the Fields dictionary:</p>
  
  <pre><code>public interface IContrivedExample
  {
      string Name { get; }
  }
  </code></pre>
  
  <p>From an interceptor, I want to get the "target" DataContainer, and return the "Name" value:</p>
  
  <pre><code>public void Intercept(IInvocation invocation)
  {
      object fieldName = omitted; // get field name based on invocation information
  
      DataContainer container = ???; // this is what I'm trying to figure out
      invocation.ReturnValue = container.Fields[fieldName];
  }
  
  // Somewhere in code
  var c = new DataContainer();
  c.Fields.Add("Name", "Jordan");
  
  var pg = new ProxyGenerator();
  IContrivedExample ice = (IContrivedExample) pg.CreateInterfaceProxyWithTarget(..., c, ...);
  Debug.Assert(ice.Name == "Jordan");
  </code></pre>
  
  <p>Any thoughts on how to get the underlying target</p>
  
  <p>Note: this is a contrived example I'm using to establish some context around the question I have.</p>