/// <summary> /// Create an exact copy of the given tree node but replace the leaf value of type T1 by a value /// 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 SimpleTreeLeaf <T2> Cast <T1, T2>(this SimpleTreeLeaf <T1> treeNode, Func <T1, T2> castFunc) { return(new SimpleTreeLeaf <T2>(castFunc(treeNode.Value))); }
/// <summary> /// Create an exact copy of the given tree node but replace the leaf value of type T1 by a value /// of type string using the ToString() method /// </summary> /// <typeparam name="T1"></typeparam> /// <param name="treeNode"></param> /// <returns></returns> public static SimpleTreeLeaf <string> ToStringTree <T1>(this SimpleTreeLeaf <T1> treeNode) { return(new SimpleTreeLeaf <string>(treeNode.Value.ToString())); }
/// <summary> /// Create an exact copy of the given tree node but replace the leaf value of type T1 by a value /// of type T2 using the as operator /// </summary> /// <typeparam name="T1"></typeparam> /// <typeparam name="T2"></typeparam> /// <param name="treeNode"></param> /// <returns></returns> public static SimpleTreeLeaf <T2> Cast <T1, T2>(this SimpleTreeLeaf <T1> treeNode) where T1 : class where T2 : class { return(new SimpleTreeLeaf <T2>(treeNode.Value as T2)); }