Check Properties of a Dynamic Object in .NET

added by tdupont
10/18/2013 12:59:52 PM

3 Kicks, 142 Views

How can you avoid a RuntimeBinderException when working with dynamics? In JavaScript, checking if an object implements a property is easy; so why can't it be that easy to check dynamics in C#? Well, it is! If you are using an ExpandoObject, you need only cast it to a Dictionary and then check if it contains the desired key.