I have a dynamic object, that I think is implemented with Clay. It has one of two possible property names. I want to use which ever property name is available. The following doesn't work:
dynamic workItemPart = item.WorkItem; // is an Orchard.ContentManagement.ContentPart
var learnMore = workItemPart.LearnMore ?? workItemPart.LearnMoreField;
It throws a Microsoft.CSharp.RuntimeBinder.RuntimeBinderException
:
does not contain a definition for 'LearnMore'
How do we check if a dynamic Clay object has a property? In JavaScript, for instance, we can do the following.
var workItemPart = {
LearnMoreField: "Sure"
}
console.log(workItemPart.LearnMore || workItemPart.LearnMoreField);
Is there anything this concise in C# with Clay?
Related:
Is Orchard.ContentManagement.ContentPart implemented with Clay?