title: How do I wrap an object in a dynamic object?
body: <p>Given an <code>System.Object</code>, how do I get a dynamic object with which to access any members it might have.</p>
  
  <p>Specifically, I want to unit test an ASP.NET MVC 3 controller action which returns a <code>JsonResult</code>. The <code>JsonResult</code> has a <code>Data</code> property of type <code>object</code>. I'm populating this object with an anonymous type:</p>
  
  <pre><code>return Json(new { Success = "Success" });
  </code></pre>
  
  <p>In my test, I want to do something like</p>
  
  <pre><code>var result = controller.Foo();
  
  Assert.That(((SomeDynamicType)result.Data).Success, Is.EqualTo("Success"));
  </code></pre>
  
  <p>How is this done?</p>
  
  <p><strong>UPDATE</strong><br>
  Though <code>result.Data</code> is of type <code>object</code>, inspecting it in the Watch window shows it has the following type:</p>
  
  <pre><code>{
      Name = "&lt;&gt;f__AnonymousType6`1" 
      FullName = "&lt;&gt;f__AnonymousType6`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"
  } 
  System.Type {System.RuntimeType}
  </code></pre>