private static List<Sample> depthSelect(Sample sample, int depth, List<Sample> parents = null)
{
if (depth <= 0)
return new List<Sample>();
List<Sample> samples = new List<Sample>();
foreach (var child in sample.Samples)
{
if (parents != null && parents.Contains(child))
continue;
samples.Add(child);
var result = depthSelect(child, depth - 1, samples);
samples.AddRange(result);
}
return samples;
}