示例#1
0
        public static IEnumerable ToValues(Type enumType, IEnumerable <string> nameCollection)
        {
            Debug.Assert(TypeInterrogator.IsEnumType(enumType));

            IList values = (IList)GenBuilder.BuildInstance(typeof(List <>), new Type[] { enumType });

            foreach (string name in nameCollection)
            {
                values.Add(Enum.Parse(enumType, name));
            }

            return(values);
        }
示例#2
0
        public static IList ToList(IEnumerable source, Type itemT)
        {
            if (TypeInterrogator.IsListType(source.GetType()))
            {
                return((IList)source);
            }

            IList target = (IList)GenBuilder.BuildInstance(typeof(List <>), new Type[] { itemT });

            foreach (object it in source)
            {
                target.Add(it);
            }

            return(target);
        }