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

            foreach (var pair in treeNode)
            {
                newTreeNode.Add(pair.Key, Cast(pair.Value, castFunc));
            }

            return(newTreeNode);
        }
Ejemplo 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 SimpleTreeBranchDictionaryByIndex <string> ToStringTree <T1>(this SimpleTreeBranchDictionaryByIndex <T1> treeNode)
        {
            var newTreeNode = new SimpleTreeBranchDictionaryByIndex <string>();

            foreach (var pair in treeNode)
            {
                newTreeNode.Add(pair.Key, ToStringTree(pair.Value));
            }

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

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

            return(newTreeNode);
        }