Borrowing from a recent (well, 2014) C# 6.0 addition, the null propagation operator, I propose the get-member-if-not-null-or-undefined-else-bail syntax - ?.
, which can shorten a lot of code -
return object?.member?.innerMember
It is an almost* equivalent syntactic sugar for -
return object && object.member && object.member.innerMember
(*This obviously checks for more than just null
or undefined
and can be problematic, but authors generally knows they are dealing with members that are objects and not other truthy values)
Or the longer -
if (object)
{
if (object.member)
{
return object.member.innerMember;
}
}