Is there a way to check if an Expando object contains a property before interacting with it. For example, If i were to say var test = Expando.Something and Something didn't exist, it will throw an exception. How do i check to see if "Something" exists in the expando object before I query it?
1 Answer
Expando objects are just an abstraction. The class inherits from IDictionary<string, object>. This class supports the ContainsKey method and this will do what you need it to do. So if you cast the expando object to a dictionary first, you can use the contains key method to check if a key exists.
Use the following if statement to check if a property exists in an expando object.
if(((IDictionary<String, object>)expandoObject).ContainsKey("SomeMember")
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String