/// <summary> /// Gets the <paramref name="startingPoint"/> (if <paramref name="returnStartingPoint"/> is true) and all of the descendants of the <paramref name="startingPoint"/>. /// </summary> /// <param name="startingPoint">The starting point</param> /// <param name="returnStartingPoint">If true, return the starting point first. Otherwise, just return the descendants.</param> /// <returns><paramref name="startingPoint"/> (if <paramref name="returnStartingPoint"/> is true) and its descendants</returns> protected static IEnumerable <AbstractProgramElement> GetDescendants(AbstractProgramElement startingPoint, bool returnStartingPoint) { if (returnStartingPoint) { yield return(startingPoint); } foreach (var element in startingPoint.GetChildren()) { foreach (var descendant in GetDescendants(element, true)) { yield return(descendant); } } }
/// <summary> /// Gets an element and all of its ancestors /// </summary> /// <param name="startingPoint">The first element to return</param> /// <returns>The <paramref name="startingPoint"/> and all of its ancestors</returns> protected static IEnumerable <AbstractProgramElement> GetAncestorsAndStartingPoint(AbstractProgramElement startingPoint) { var current = startingPoint; while (null != current) { yield return(current); current = current.GetParent(); } }