private int SumValue() { if (!SubNodes.Any()) { return(Metadata.Sum()); } var output = 0; foreach (var item in Metadata) { if (item < 1 || item > SubNodes.Count()) { continue; } output += SubNodes[item - 1].SumValue(); } return(output); }