Error message first
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'System.Collections.Generic.List' does not contain a definition for 'First' in CallSite.Target (Closure, CallSite, Object) in System.Dynamic.UpdateDelegates.UpdateAndExecute1 (CallSite site, T0 arg0) in ClaySharp.Tests.ToPropertyDictionaryTests.TestExpando () in ToPropertyDictionaryTests.cs: line 91
Test:
[Test]
public void TestExpando()
{
dynamic root = new ExpandoObject();
root.Name = "Name";
var result = GetExpandos();
root.Child = result;
var first = root.Child.First();
Assert.That(first.Name, Is.EqualTo("Obj1"));
}
private IEnumerable<dynamic> GetExpandos()
{
var toReturn = new List<dynamic>();
dynamic obj1 = new ExpandoObject();
toReturn.Add(obj1);
obj1.Name = "Obj1";
dynamic obj2 = new ExpandoObject();
toReturn.Add(obj2);
obj2.Name = "Obj2";
return toReturn;
}
The interesting part is that if the “root” is removed from the image and the test is run against the “result”, how does it work perfectly.
And now for the very strange part. Debugging - setpoint before returning toReturn. Take a look at this, it works
? ToReturn.GetType (). Fullname
"System.Collections.Generic.List`1 [[System.Object, mscorlib, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089]]"
? ToReturn
Count = 2 [0]: {System.Dynamic.ExpandoObject} [1]: {System.Dynamic.ExpandoObject}
? ToReturn.First()
{System.Dynamic.ExpandoObject}
, "root",
?
Count = 2 [0]: {System.Dynamic.ExpandoObject} [1]: {System.Dynamic.ExpandoObject}
? Result.First()
{System.Dynamic.ExpandoObject}
, root,
? Root.Child
{System.Collections.Generic.List} [0]: {System.Dynamic.ExpandoObject} [1]: {System.Dynamic.ExpandoObject}
? Root.Child.First()