When working with dynamic objects in many languages, there is a construct that allows you to get the value of a property and if said property doesn't exist, return a default value.
I want to know if there is a similar method/syntax when working with dynamic in .NET. I know that you can cast an ExpandoObject to a Dictionary, but sometimes there is no guarantee that a dynamic object is an Expando.
I'm thinking of something that would have the same effect of the following code
public class SomeClass
{
public string ValidProperty { get; set; }
}
dynamic t = new SomeClass() {
ValidProperty = "someValue"
};
Console.WriteLine(t.Get("ValidProperty", "doesn't exist")); // Prints 'someValue'
Console.WriteLine(t.Get("InvalidProperty", "doesn't exist")); // Prints 'doesn't exist'