I have an anonymous type object that I receive as a dynamic from a method I would like to check in a property exists on that object.
.... var settings = new
Using reflection, this is the function i use :
public static bool doesPropertyExist(dynamic obj, string property) { return ((Type)obj.GetType()).GetProperties().Where(p => p.Name.Equals(property)).Any(); }
then..
if (doesPropertyExist(myDynamicObject, "myProperty")){ // ... }