예제 #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 SimpleTreeBranchList <T2> Cast <T1, T2>(this SimpleTreeBranchList <T1> treeNode, Func <T1, T2> castFunc)
        {
            var newTreeNode = new SimpleTreeBranchList <T2>();

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

            return(newTreeNode);
        }
예제 #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 SimpleTreeBranchList <string> ToStringTree <T1>(this SimpleTreeBranchList <T1> treeNode)
        {
            var newTreeNode = new SimpleTreeBranchList <string>();

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

            return(newTreeNode);
        }
예제 #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 SimpleTreeBranchList <T2> Cast <T1, T2>(this SimpleTreeBranchList <T1> treeNode)
            where T1 : class
            where T2 : class
        {
            var newTreeNode = new SimpleTreeBranchList <T2>();

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

            return(newTreeNode);
        }