Ejemplo n.º 1
0
        /// <summary>
        /// 转换
        /// </summary>
        /// <typeparam name="TIn">输入元素类型</typeparam>
        /// <typeparam name="TOut">输出元素类型</typeparam>
        /// <param name="value">值</param>
        /// <param name="handler">委托方法</param>
        public static Tree <TOut> To <TIn, TOut>(this Tree <TIn> value, ToHandler <TIn, TOut> handler)
        {
            if (value == null)
            {
                return(new Tree <TOut>());
            }
            if (value.Subsets.IsEmpty())
            {
                return(new Tree <TOut>(handler(value.Data), null, value.SortId));
            }
            var subsets = new List <Tree <TOut> >();

            foreach (var item in value.Subsets)
            {
                subsets.Add(item.To(handler));
            }
            return(new Tree <TOut>(handler(value.Data), subsets.OrderBy(t => t.SortId).ToList(), value.SortId));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 转换
 /// </summary>
 /// <typeparam name="TIn">输入元素类型</typeparam>
 /// <typeparam name="TOut">输出元素类型</typeparam>
 /// <param name="value">值</param>
 /// <param name="handler">委托方法</param>
 public static List <Tree <TOut> > To <TIn, TOut>(this List <Tree <TIn> > value, ToHandler <TIn, TOut> handler)
 {
     if (value == null)
     {
         return(new List <Tree <TOut> >());
     }
     return(value.Select(t => t.To(handler)).OrderBy(t => t.SortId).ToList());
 }