Is there any way I can assign to a property belonging to a member property, without using a conditional statement such as if
? UIElement is a class and I am using nullable reference types.
For example:
public UIElement? Content { get; set; }
public override void LayoutChildren()
{
Content.Size = Size;
}
However, if Content
is null, then that will throw a null reference exception. I could, of course use:
if (Content is not null)
Content.Size = Size;
But that requires a bulky and ugly if
statement to do a simple thing.
What I want to achieve is something like this:
Content?.Size = Size;
Without using any helper methods (such as an AssignIfNotNull()
method) or similar.