Add property to ExpandoObject with the same name as a string

前端 未结 2 1883
萌比男神i
萌比男神i 2021-02-01 15:55

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         


        
2条回答
  •  醉梦人生
    2021-02-01 16:39

    ExpandoObject implements IDictionary:

    ((IDictionary)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.

提交回复
热议问题