Esempio n. 1
0
        /// <summary>
        /// GetFieldTag 获得指定枚举值的Tag。
        /// </summary>
        /// <param name="enumValue"></param>
        /// <returns></returns>
        public static object GetFieldTag(object enumValue)
        {
            IList <EnumDescription> list = EnumDescription.DoGetFieldTexts(enumValue.GetType());

            if (list == null)
            {
                return(null);
            }

            return(CollectionConverter.ConvertFirstSpecification <EnumDescription, object>(list, delegate(EnumDescription ed) { return ed.Tag; }, delegate(EnumDescription ed) { return ed.enumValue.ToString() == enumValue.ToString(); }));
        }
Esempio n. 2
0
        /// <summary>
        /// GetEnumValueByTag 根据描述Tag获取对应的枚举值
        /// </summary>
        public static object GetEnumValueByTag(Type enumType, object tag)
        {
            IList <EnumDescription> list = EnumDescription.DoGetFieldTexts(enumType);

            if (list == null)
            {
                return(null);
            }

            return(CollectionConverter.ConvertFirstSpecification <EnumDescription, object>(list, delegate(EnumDescription des) { return des.enumValue; }, delegate(EnumDescription des) { return des.tag.ToString() == tag.ToString(); }));
        }
        /// <summary>
        /// GetUnion 高效地求两个List元素的并集。
        /// </summary>
        public static List <T> GetUnion <T>(IList <T> list1, IList <T> list2)
        {
            SortedDictionary <T, int> result = new SortedDictionary <T, int>();

            foreach (T tmp in list1)
            {
                if (!result.ContainsKey(tmp))
                {
                    result.Add(tmp, 0);
                }
            }

            foreach (T tmp in list2)
            {
                if (!result.ContainsKey(tmp))
                {
                    result.Add(tmp, 0);
                }
            }

            return((List <T>)CollectionConverter.CopyAllToList <T>(result.Keys));
        }
 /// <summary>
 /// ConvertAll 将source中的每个元素转换为TResult类型
 /// </summary>
 public static IList <TResult> ConvertAll <TObject, TResult>(IEnumerable <TObject> source, Func <TObject, TResult> converter)
 {
     return(CollectionConverter.ConvertSpecification <TObject, TResult>(source, converter, null));
 }