示例#1
0
        /// <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));
        }
示例#2
0
        /// <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>());
        }
示例#3
0
        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
            });
        }
示例#4
0
        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);
                }
            }
        }
示例#5
0
        /// <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)));
        }
示例#6
0
        /// <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());
        }