Example #1
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>());
        }
Example #2
0
        /// <summary>
        /// Returns a collection of ancestors of specified object.
        /// </summary>
        /// <param name="service"></param>
        /// <param name="o"></param>
        /// <returns></returns>
        public static IEnumerable <T> GetAncestors <T>(this IHierarchyService <T> service, T o)
        {
            ThrowIfInvalidArgs(service, o);

            while (true)
            {
                o = service.GetParent(o);
                if (o != null)
                {
                    yield return(o);
                }
                else
                {
                    break;
                }
            }
        }
Example #3
0
        /// <summary>
        /// Determines whether specified object is the root object.
        /// </summary>
        /// <param name="service"></param>
        /// <param name="o"></param>
        /// <returns></returns>
        public static bool IsRoot <T>(this IHierarchyService <T> service, T o)
        {
            ThrowIfInvalidArgs(service, o);

            return(service.GetParent(o) == null);
        }