示例#1
0
文件: ToIList.cs 项目: isensen/Peanut
        public object Parse(NameValueCollection data, string key, string prefix, out bool succeed)
        {
            IList <T> list = null;

            succeed = true;
            Type type = Type.GetType("System.Collections.Generic.List`1");

            type = type.MakeGenericType(new Type[]
            {
                typeof(T)
            });
            list = (IList <T>)Activator.CreateInstance(type);
            int num = 0;
            Dictionary <PropertyInfo, string[]> dictionary = new Dictionary <PropertyInfo, string[]>();

            foreach (PropertyInfo current in ToIList <T> .Properties)
            {
                string[] array = BindUtils.GetValues(data, current.Name, prefix);
                if (array != null && array.Length > num)
                {
                    num = array.Length;
                }
                dictionary.Add(current, array);
            }
            for (int i = 0; i < num; i++)
            {
                NameValueCollection nameValueCollection = new NameValueCollection();
                foreach (PropertyInfo current in ToIList <T> .Properties)
                {
                    string[] array = dictionary[current];
                    if (array != null && i < array.Length)
                    {
                        nameValueCollection.Add(current.Name, array[i]);
                    }
                }
                T item = BinderHelper.CreateInstance <T>(nameValueCollection);
                list.Add(item);
            }
            return(list);
        }
示例#2
0
 internal static T CreateInstance <T>(NameValueCollection data, string prefix)
 {
     return((T)BinderHelper.CreateInstance(typeof(T), data, prefix));
 }
示例#3
0
 internal static T CreateInstance <T>(NameValueCollection data)
 {
     return(BinderHelper.CreateInstance <T>(data, null));
 }
示例#4
0
 internal static object CreateInstance(Type type, NameValueCollection data)
 {
     return(BinderHelper.CreateInstance(type, data, null));
 }