Is there a way to add a property to an ExpandoObject with the same name as a string value?
For example, if I have:
string propName = \"ProductNumber\";
d
Cast the ExpandoObject
to an IDictionary<string,object>
to do this:
string propName = "ProductNumber";
dynamic obj = new System.Dynamic.ExpandoObject();
var dict = (IDictionary<string,object>)obj;
dict[propName] = 123;
ExpandoObject implements IDictionary<string, object>
:
((IDictionary<string, object>)obj)[propName] = propValue
I don't know off the top of my head whether you can use the indexer syntax with a dynamic
reference (i.e., without the cast), but you can certainly try it and find out.