Reputation: 163
I do not know how to refactor this expression.
TreeViewItemNode FindNode(TreeViewItemNode nodeCollection)
{
foreach (var child in nodeCollection.Children)
{
var found = FindNodeContainingVarId(child, varId);
if (found != null)
return found;
}
return null;
}
Upvotes: 0
Views: 50
Reputation: 11389
First select the node and take the first found node or null if no node was found like:
TreeViewItemNode FindNode(TreeViewItemNode nodeCollection)
{
return nodeCollection.Children
.Select(child => FindNodeContainingVarId(child, varId).
.FirstOrDefault(node => node != null);
}
Upvotes: 1