title: Obtain containing object instance from ModelMetadataProvider in ASP.NET MVC
body: <p>Implementing custom <code>DataAnnotationsModelMetadataProvider</code> in ASP.NET MVC2.</p>
  
  <p>Assuming the object that is being rendered looks like this:</p>
  
  <pre><code>- Contact : IUpdateable
     - Name: string
     - ContactType: (Lead, Prospect, Customer)
  </code></pre>
  
  <p>and the method below is in the context of <code>Contact.ContactType</code> meaning that:</p>
  
  <ul>
  <li><code>meta.PropertyName  == "ContactType"</code></li>
  <li><code>meta.ContainerType == typeof(Contact)</code></li>
  <li><code>meta.Model         == ContactType.Lead</code></li>
  </ul>
  
  <p>(the code under question:)</p>
  
  <pre><code>protected override ModelMetadata CreateMetadata(IEnumerable&lt;Attribute&gt; attributes, 
      Type containerType,
      Func&lt;object&gt; modelAccessor, 
      Type modelType, string propertyName) {
  
      var containerInstance = meta.NotSureWhatGoesHere as IUpdateable;
      meta.IsReadOnly = containerInstance != null &amp;&amp; containerInstance.CanBeUpdated(meta.PropertyName);
  }
  </code></pre>
  
  <p><strong>The question</strong>: How can I obtain the <em>instance</em> of Contact from the metadata? (replace <code>NotSureWhatGoesHere</code> with the correct one)?</p>
  
  <p>Thanks.</p>