dynamic Objects with variables in c# -
is possible build dynamic objects having property name set value of variable?
for instance seems standard...
dynamic elem = new object(); elem.name = "myname";
but how implemented?...
string fn = "firstname"; string ln = "lastname"; dynamic elem = new object(); elem.fn = "john"; elem.ln = "doe";
where able call properties like...
string fn = elem.firstname;
the expandoobject implements idictionary<string, object>
, meaning can add properties using string key.
dynamic person = new expandoobject(); person.firstname = "alex"; var ln = "lastname"; (person idictionary<string, object>)[ln] = "keysmith";
Comments
Post a Comment