예제 #1
0
 public object Parse(NameValueCollection data, string key, string prefix, out bool succeed)
 {
     string[] array = BindUtils.GetValues(data, key, prefix);
     succeed = true;
     if (array == null)
     {
         array = new string[0];
     }
     return(array);
 }
예제 #2
0
        public object Parse(NameValueCollection data, string key, string prefix, out bool succeed)
        {
            Array array = Array.CreateInstance(typeof(T), 0);

            string[] values = BindUtils.GetValues(data, key, prefix);
            if (values != null)
            {
                array = Array.CreateInstance(typeof(T), values.Length);
                for (int i = 0; i < values.Length; i++)
                {
                    IEnumValue enumConvert = BindUtils.GetEnumConvert(typeof(T));
                    array.SetValue(enumConvert.GetValue(values[i], out succeed), i);
                }
            }
            succeed = true;
            return(array);
        }
예제 #3
0
 public object Parse(NameValueCollection data, string key, string prefix, out bool succeed)
 {
     T[] array = new T[0];
     succeed = true;
     string[] values = BindUtils.GetValues(data, key, prefix);
     succeed = (values != null && values.Length > 0);
     if (values != null)
     {
         array = new T[values.Length];
         for (int i = 0; i < values.Length; i++)
         {
             T t;
             if (this.Parse(values[i], out t))
             {
                 array[i] = t;
             }
         }
     }
     return(array);
 }
예제 #4
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);
        }