Example #1
0
        public static IEnumerable <T> GetChildren <T>(this IVortexObject obj, IEnumerable <object> excluding) where T : IVortexObject
        {
            if (excluding == null)
            {
                excluding = new List <Type>();
            }

            var children = obj.GetChildren().Where(p => p is T && !excluding.Any(e => e != p)).Select(p => (T)p);

            return(children);
        }
        /// <summary>
        /// Searches recursively the children of this <see cref="IVortexObject"/>
        /// </summary>
        /// <remarks>
        /// Take into consideration possible performance degradation due to use of reflections in this method.
        /// </remarks>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj">Searched object</param>
        /// <param name="children">[optional] Pre-existing children. </param>
        /// <returns>Children of this object.</returns>
        public static IEnumerable <T> GetDescendants <T>(this IVortexObject obj, IList <T> children = null) where T : IVortexObject
        {
            children = children != null ? children : new List <T>();

            if (obj is Vortex.Connector.IVortexObject && obj != null)
            {
                foreach (var child in obj.GetChildren())
                {
                    if (child is T)
                    {
                        children.Add((T)obj);
                    }

                    GetDescendants <T>(child, children);
                }
            }

            return(children);
        }
Example #3
0
        /// <summary>
        /// Searches recursively the children of this <see cref="IVortexObject"/>
        /// </summary>
        /// <remarks>
        /// Take into consideration possible performance degradation due to use of reflections in this method.
        /// </remarks>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj">Searched object</param>
        /// <param name="children">[optional] Pre-existing children. </param>
        /// <returns>Children of this object.</returns>
        public static IEnumerable <T> GetDescendants <T>(this IVortexObject obj, IList <T> children = null) where T : class
        {
            children = children != null ? children : new List <T>();

            if (obj != null)
            {
                foreach (var child in obj.GetChildren())
                {
                    var ch = child as T;
                    if (ch != null)
                    {
                        children.Add(ch);
                    }

                    GetDescendants <T>(child, children);
                }
            }

            return(children);
        }
Example #4
0
        /// <summary>
        /// Gets descendant objects of given type up to given tree depth.
        /// </summary>
        /// <remarks>
        /// Take into consideration possible performance degradation due to use of reflections in this method.
        /// </remarks>
        /// <typeparam name="T">Descendant type</typeparam>
        /// <param name="obj">Root object</param>
        /// <param name="depth">Depth to search for descendant objects</param>
        /// <param name="children">[optional] Pre-existing descendants.</param>
        /// <param name="currentDepth">[optional] Current depth</param>
        /// <returns>Descendant of given type up to given depth.</returns>
        public static IEnumerable <T> GetDescendants <T>(this IVortexObject obj, int depth, IList <T> children = null, int currentDepth = 0) where T : class
        {
            children = children != null ? children : new List <T>();

            currentDepth++;

            if (obj != null && currentDepth < depth)
            {
                foreach (var child in obj.GetChildren())
                {
                    var ch = child as T;
                    if (ch != null)
                    {
                        children.Add(ch);
                    }

                    GetDescendants <T>(child, depth, children, currentDepth);
                }
            }

            currentDepth--;

            return(children);
        }
Example #5
0
        /// <summary>
        /// Get the children of given type of this <see cref="IVortexObject"/>
        /// </summary>
        /// <remarks>
        /// Take into consideration possible performance degradation due to use of reflections in this method.
        /// </remarks>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj">Searched object</param>
        /// <returns>Children of this object.</returns>
        public static IEnumerable <T> GetChildren <T>(this IVortexObject obj) where T : IVortexObject
        {
            var children = obj.GetChildren().Where(p => p is T).Select(p => (T)p);

            return(children);
        }
 public IEnumerable <IVortexObject> GetChildren()
 {
     return(_obj.GetChildren());
 }