/// <summary> /// Retrieves the descendant children of specified object. /// </summary> /// <param name="service"></param> /// <param name="o"></param> /// <returns></returns> public static IEnumerable <T> GetDescendants <T>(this IHierarchyService <T> service, T o) { ThrowIfInvalidArgs(service, o); var stack = new Stack <T>(service.GetChildren(o).Reverse()); return(GetDescendantsAndSelf(service, stack)); }
/// <summary> /// Returns a collection of the siblings after specified object. /// </summary> /// <param name="service"></param> /// <param name="o"></param> /// <returns></returns> public static IEnumerable <T> GetObjectsAfterSelf <T>(this IHierarchyService <T> service, T o) where T : class { ThrowIfInvalidArgs(service, o); var parent = service.GetParent(o); if (parent != null) { return(service.GetChildren(parent).SkipWhile(c => c != o).Skip(1)); } return(Enumerable.Empty <T>()); }
public async Task <VmPage <VmHierarchy> > GetChildren(int id) { var result = await _hierarchyService.GetChildren(id); return(new VmPage <VmHierarchy> { Items = VmHierarchy.Build(result), PageIndex = 1, PageSize = 1, TotalCount = result.Count }); }
private static IEnumerable <T> GetDescendantsAndSelf <T>(this IHierarchyService <T> service, Stack <T> stack) { while (stack.Count > 0) { var o = stack.Pop(); yield return(o); foreach (var child in service.GetChildren(o).Reverse()) { stack.Push(child); } } }
/// <summary> /// Determines whether the object has grandchildren. /// </summary> /// <param name="service"></param> /// <param name="o"></param> /// <returns></returns> public static bool HasGrandchildren <T>(this IHierarchyService <T> service, T o) { ThrowIfInvalidArgs(service, o); return(service.GetChildren(o).Any(c => !service.IsLeaf(c))); }
/// <summary> /// Determines whether the object is a leaf object, meaning it has no children. /// </summary> /// <param name="service"></param> /// <param name="o"></param> /// <returns></returns> public static bool IsLeaf <T>(this IHierarchyService <T> service, T o) { ThrowIfInvalidArgs(service, o); return(!service.GetChildren(o).Any()); }