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

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -