0

Here's my razor code:

<div>Creation date:</div>
<div>@Model.DynamicData.CreationDate</div>

DynamicData is an ExpandoObject on the Model. And if it does not have the CreationDate property I get this error:

RuntimeBinderException: 'System.Dynamic.ExpandoObject' does not contain a definition for 'CreationDate'

Since checking the availability of properties on expando objects is verbose, how can I use Optional Chaining on expando objects?

Ali EXE
  • 853
  • 1
  • 7
  • 21
  • 1
    Does this answer your question? [How to detect if a property exists on an ExpandoObject?](https://stackoverflow.com/questions/2839598/how-to-detect-if-a-property-exists-on-an-expandoobject) – SᴇM Nov 05 '21 at 07:11
  • @SᴇM, that code is not `Optional Chaining` buddy. Please read the question carefully. – Ali EXE Nov 05 '21 at 08:17
  • Optional Chaining checks if the property is `null`, not if it exists or not. For example, you can write your own extension method to check if the property exists. – SᴇM Nov 05 '21 at 08:22

0 Answers0