Shorthand for nested null checking C#
- by Myster
As far as I know there is not a significantly more elegant way to write the following....
string src;
if((ParentContent!= null)
&&(ParentContent.Image("thumbnail") != null)
&&(ParentContent.Image("thumbnail").Property("src") != null))
src = ParentContent.Image("thumbnail").Property("src").Value
Do you think there should be a C# language feature to make this shorter?
And if so, what should it look like?
for example, something like extending the ?? operator
string src = ParentContent??.Image("thumbnail")??.Property("width")??.Value;
Apologies for the rather contrived example, and my over-simplified solution.