通常情况下,我们可以像这样创建属性:
dynamic expando = new ExpandoObject();
expando.Price = 45k;
expando.Value = "Good";
在我的情况下,我只有在运行时才能知道像“价格”或“价值”等属性。那么,我该如何创建这样的动态属性呢?就像这样:
dynamic expando = new ExpandoObject();
expando[properties[0]] = 45k;
expando[properties[1]] = "Good";
expando[properties[2]] = "Red";
expando[properties[3]] = 8;
无论如何实现这种行为。