Try:
dynamic yourExpando = new ExpandoObject(); if (((IDictionary<string, Object>)yourExpando).ContainsKey("Id")) { //Has property... }
ExpandoObject explicitly implements IDictionary<string, Object> , where the key is the name of the property. Then you can check if the dictionary contains a key. You can also write a small helper method if you need to perform this kind of check often:
private static bool HasAttr(ExpandoObject expando, string key) { return ((IDictionary<string, Object>) expando).ContainsKey(key); }
And use it like this:
if (HasAttr(yourExpando, "Id")) { //Has property... }
vcsjones
source share