I am trying to call a property that may or may not be defined for the current document type: Model.PageTitle
When it's not defined, I get "'umbraco.MacroEngines.DynamicNode' does not contain a definition for 'PageTitle'". I've tried testing if Model.PageTitle is null, but that didn't help. The only way I've found to hide the error is throwing it in a try-catch block, which isn't ideal.
In the final, if the property isn't fetched, I return an empty DynamicNodeList
The cause of the bug is similar to the reason that .nodeTypeAlias crashes when there's no nodes
I don't like to return null in DynamicNode because it breaks chaining. One null return and your whole razor file will stop with a cannot invoke on a null reference (or something similar to that)
I'll add a HasProperty("propertyName") => bool helper
How can I test if a property exists?
I am trying to call a property that may or may not be defined for the current document type: Model.PageTitle
When it's not defined, I get "'umbraco.MacroEngines.DynamicNode' does not contain a definition for 'PageTitle'". I've tried testing if Model.PageTitle is null, but that didn't help. The only way I've found to hide the error is throwing it in a try-catch block, which isn't ideal.
Any better way?
In the final, if the property isn't fetched, I return an empty DynamicNodeList
The cause of the bug is similar to the reason that .nodeTypeAlias crashes when there's no nodes
I don't like to return null in DynamicNode because it breaks chaining. One null return and your whole razor file will stop with a cannot invoke on a null reference (or something similar to that)
I'll add a HasProperty("propertyName") => bool helper
Excellent, that is the best I could hope for! And you're very correct about returning nulls, solution sounds great.
is working on a reply...