The most dynamic types ins C# rely on
IDictionary<string,object>
Not necessarily. ExpandoObject
does, but there are plenty of other ways of being dynamic, and DynamicObject
doesn't.
Note that reference conversion casting doesn't change the type of an object. So where you've got this line:
var o = (DynamicObject) webmatrixRecord;
... the type of the variable will be DynamicObject
, but that doesn't change the type of the object that the value of o
refers to.
For your other casts, it seems that it just doesn't implement IDictionary<string, object>
, so you can't cast to it. You could use DynamicObject.GetDynamicMemberNames
to get the dynamic names, and then use DynamicObject.TryGetMember
to get the values. It's not ideal though - I would personally try to avoid even having the requirement, if possible...