How to detect if a property exists on an ExpandoObject?
c#, dynamic, expandoobject
Solution
According to MSDN the declaration shows it is implementing IDictionary:
public sealed class ExpandoObject : IDynamicMetaObjectProvider,
IDictionary<string, Object>, ICollection<KeyValuePair<string, Object>>,
IEnumerable<KeyValuePair<string, Object>>, IEnumerable, INotifyPropertyChanged
You can use this to see if a member is defined:
var expandoObject = ...;
if(((IDictionary<String, object>)expandoObject).ContainsKey("SomeMember")) {
// expandoObject.SomeMember exists.
}
Problem
In javascript you can detect if a property is defined by using the undefined keyword: ``` if( typeof data.myProperty == "undefined" ) ... ``` How would you do this in C# using the dynamic keyword with an `ExpandoObject` and without throwing an exception?