I have something like the following method.
public Node? GetLastNode(bool createNewIfEmpty = false)
{
// Return last node if any
if (Nodes.Count > 0)
return Nodes[Nodes.Count - 1];
// Return a new appended node, if requested
if (createNewIfEmpty)
{
Nodes.Add(new Node());
return Nodes[0];
}
// Otherwise, return null
return null;
}
With nullable reference types on, is there any attribute (or other way) to specify that this method never returns null as long as the createNewIfEmpty
parameter is true
?