How to dynamically get a property by name from a C# ExpandoObject?

ExpandoObject provides access both via dynamic and via IDictionary<string,object> – so you could just use the dictionary API:

var byName = (IDictionary<string,object>)account.features;
bool val = (bool)byName["isEmailEnabled"];

Or if the name is fixed, just:

bool val = ((dynamic)account).features.isEmailEnabled;

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)