public object Parse(System.Collections.Specialized.NameValueCollection data, string key, string prefix, out bool succeed) { Array result = Array.CreateInstance(EnumType, 0); object value; string[] values = ConverCore.GetValues(data, key, prefix); if (values != null) { result = Array.CreateInstance(EnumType, values.Length); for (int i = 0; i < values.Length; i++) { if (string.IsNullOrEmpty(values[i])) { result.SetValue(Enum.GetValues(EnumType).GetValue(0), i); } else { result.SetValue(Enum.Parse(EnumType, values[i]), i); } } } succeed = true; return(result); }
public object Parse(System.Collections.Specialized.NameValueCollection data, string key, string prefix, out bool succeed) { string[] values = ConverCore.GetValues(data, key, prefix); succeed = true; if (values == null) { values = new string[0]; } return(values); }
public object Parse(System.Collections.Specialized.NameValueCollection data, string key, string prefix, out bool succeed) { T[] results = new T[0]; T result; succeed = true; string[] values = ConverCore.GetValues(data, key, prefix); succeed = (values != null && values.Length > 0); if (values != null) { results = new T[values.Length]; for (int i = 0; i < values.Length; i++) { if (Parse(values[i], out result)) { results[i] = result; } } } return(results); }
public object Parse(System.Collections.Specialized.NameValueCollection data, string key, string prefix, out bool succeed) { IList <T> items = null; succeed = true; System.Type itemstype = System.Type.GetType("System.Collections.Generic.List`1"); itemstype = itemstype.MakeGenericType(typeof(T)); items = (IList <T>)Activator.CreateInstance(itemstype); int count = 0; string[] values; Dictionary <System.Reflection.PropertyInfo, string[]> valueCollection = new Dictionary <System.Reflection.PropertyInfo, string[]>(); foreach (System.Reflection.PropertyInfo pi in Properties) { values = ConverCore.GetValues(data, pi.Name, prefix); if (values != null && values.Length > count) { count = values.Length; } valueCollection.Add(pi, values); } for (int i = 0; i < count; i++) { System.Collections.Specialized.NameValueCollection itemdata = new System.Collections.Specialized.NameValueCollection(); foreach (System.Reflection.PropertyInfo pi in Properties) { values = valueCollection[pi]; if (values != null && i < values.Length) { itemdata.Add(pi.Name, values[i]); } } T item = BinderAdapter.CreateInstance <T>(itemdata); items.Add(item); } return(items); }