title: Casting anonymous type to dynamic
body: <p>I have a function that returns an anonymous type which I want to test in my MVC controller.</p>
  
  <pre><code>public JsonResult Foo()
  {
      var data = new
                    {
                        details = "something",
                        more = "More"
                    };
      return Json(data);
  }
  </code></pre>
  
  <p>I want to verify the data I get from the Foo function, What I'm doing now is getting the data type and get it's properties values with reflection. </p>
  
  <pre><code>[Test]
  public void TestOne()
  {
      var data = _controller.Foo().Data;
      var details = data.GetType().GetProperty("details").GetValue(data, null);
      var more = data.GetType().GetProperty("more").GetValue(data, null);
  
      Assert.AreEquals("something", details);
      Assert.AreEquals("More", more);
  }
  </code></pre>
  
  <p>Is there a simple way similar to this to check the anonymous properties?</p>
  
  <pre><code>[Test]
  public void TestTwo()
  {
      var data = (dynamic) _controller.Foo().Data;
      var details = data.details; // RunTimeBinderException object does not contain definition for details
      var more = data.more;
  
      Assert.AreEquals("something", details);
      Assert.AreEquals("More", more);
  }
  </code></pre>