Exemplo n.º 1
0
        /// <summary>
        /// Create an exact copy of the given tree node but replace all leaf values of type T1 by values
        /// of type T2 using the given cast function
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <param name="treeNode"></param>
        /// <param name="castFunc"></param>
        /// <returns></returns>
        public static SimpleTreeNodeList <T2> Cast <T1, T2>(this SimpleTreeNodeList <T1> treeNode, Func <T1, T2> castFunc)
        {
            var newTreeNode = new SimpleTreeNodeList <T2>();

            foreach (var item in treeNode)
            {
                newTreeNode.Add(Cast(item, castFunc));
            }

            return(newTreeNode);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create an exact copy of the given tree node but replace all leaf values of type T1 by values
        /// of type string using the ToString() method
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <param name="treeNode"></param>
        /// <returns></returns>
        public static SimpleTreeNodeList <string> ToStringTree <T1>(this SimpleTreeNodeList <T1> treeNode)
        {
            var newTreeNode = new SimpleTreeNodeList <string>();

            foreach (var item in treeNode)
            {
                newTreeNode.Add(ToStringTree(item));
            }

            return(newTreeNode);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create an exact copy of the given tree node but replace all leaf values of type T1 by values
        /// of type T2 using the as operator
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <param name="treeNode"></param>
        /// <returns></returns>
        public static SimpleTreeNodeList <T2> Cast <T1, T2>(this SimpleTreeNodeList <T1> treeNode)
            where T1 : class
            where T2 : class
        {
            var newTreeNode = new SimpleTreeNodeList <T2>();

            foreach (var item in treeNode)
            {
                newTreeNode.Add(Cast <T1, T2>(item));
            }

            return(newTreeNode);
        }