Ejemplo n.º 1
0
        public static object ToList(this IEnumerable collection, Type listType)
        {
            ExceptionHelpers.ThrowArgumentExceptionIf("listType", !TypeSystem.ContainsInterface(listType, typeof(IList)), Resources.NotValidListType, new object[0]);
            IList lists = TypeSystem.CreateInstance(listType) as IList;

            foreach (object obj in collection)
            {
                lists.Add(obj);
            }
            return(lists);
        }
Ejemplo n.º 2
0
        public static object ToDictionary(this IEnumerable collection, Type dictionaryType)
        {
            ExceptionHelpers.ThrowArgumentExceptionIf("dictionaryType", !TypeSystem.ContainsInterface(dictionaryType, typeof(IDictionary)), Resources.NotValidDictionaryType, new object[0]);
            IDictionary dictionaries = TypeSystem.CreateInstance(dictionaryType) as IDictionary;

            foreach (object obj in collection)
            {
                object propertyValue  = TypeSystem.GetPropertyValue(obj, "Key", true);
                object propertyValue1 = TypeSystem.GetPropertyValue(obj, "Value", true);
                dictionaries.Add(propertyValue, propertyValue1);
            }
            return(dictionaries);
        }