public static object GetValue(Type type, string key) { object result = null; IConvert convert = null; object obj = null; if (!BindUtils.Converts.TryGetValue(type, out convert)) { if (type.IsEnum) { Type type2 = typeof(ToEnum <>).MakeGenericType(new Type[] { type }); convert = (IConvert)Activator.CreateInstance(type2); BindUtils.AddCustomConvert(type, convert); } } bool flag = false; if (convert != null) { obj = convert.Parse(HttpContext.Current.Request.Params, key, null, out flag); } if (flag) { result = obj; } return(result); }
public object Parse(NameValueCollection data, string key, string prefix, out bool succeed) { string value = BindUtils.GetValue(data, key, prefix); bool flag = false; succeed = bool.TryParse(value, out flag); return(flag); }
public static void AddCustomConvert(params Assembly[] assemblies) { for (int i = 0; i < assemblies.Length; i++) { Assembly ass = assemblies[i]; BindUtils.LoadConvertByAssembly(ass); } }
public object Parse(NameValueCollection data, string key, string prefix, out bool succeed) { string value = BindUtils.GetValue(data, key, prefix); DateTime dateTime; succeed = DateTime.TryParse(value, out dateTime); return(dateTime); }
public object Parse(NameValueCollection data, string key, string prefix, out bool succeed) { string value = BindUtils.GetValue(data, key, prefix); decimal num = 0m; succeed = decimal.TryParse(value, out num); return(num); }
public object Parse(NameValueCollection data, string key, string prefix, out bool succeed) { string value = BindUtils.GetValue(data, key, prefix); byte b = 0; succeed = byte.TryParse(value, out b); return(b); }
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); }
private bool GetClassValue(System.Collections.Specialized.NameValueCollection data, string Prefix, out object value) { IConvert convert = null; value = null; Type createtype = Info.ParameterType; if (Binder != null && Binder.Convert == null && Binder.Fungible != null) { createtype = Binder.Fungible; } bool succed = false; if (Binder != null && !string.IsNullOrEmpty(Binder.Prefix)) { Prefix = Binder.Prefix; } if (Binder != null) { convert = Binder.GetConvert(); } if (convert == null) { if (BindUtils.Converts.ContainsKey(createtype)) { convert = BindUtils.Converts[createtype]; } } if (convert != null) { value = convert.Parse(data, Info.Name, Prefix, out succed); } else if (createtype.IsArray) { if (createtype.GetElementType().IsEnum) { Type toenumtype = typeof(ToEnumArray <>).MakeGenericType(createtype.GetElementType()); IConvert tea = (IConvert)Activator.CreateInstance(toenumtype); BindUtils.AddCustomConvert(toenumtype, tea); value = tea.Parse(data, Info.Name, Prefix, out succed); } } else { if (createtype.IsClass && !createtype.IsInterface && !createtype.IsAbstract) { ClassBinder cb = BindUtils.GetBinder(createtype); succed = true; value = cb.CreateObject(data, Prefix); } } return(succed); }
private static void LoadConverts() { lock (typeof(BindUtils)) { if (BindUtils.mConverts == null) { BindUtils.mConverts = new Dictionary <Type, IConvert>(); BindUtils.LoadBaseConvert(); } } }
public bool GetClassValue(System.Collections.Specialized.NameValueCollection data, string Prefix, out object value) { IConvert convert = null; value = null; Type createtype = Handler.Property.PropertyType; if (Binder != null && Binder.Convert == null && Binder.Fungible != null) { createtype = Binder.Fungible; } bool succed = false; if (Binder != null && !string.IsNullOrEmpty(Binder.Prefix)) { Prefix = Binder.Prefix; } if (Binder != null) { convert = Binder.GetConvert(); } if (convert == null) { if (BindUtils.Converts.ContainsKey(createtype)) { convert = BindUtils.Converts[createtype]; } } if (convert != null) { value = convert.Parse(data, Handler.Property.Name, Prefix, out succed); } else { if (createtype.IsClass && !createtype.IsInterface && !createtype.IsAbstract) { if (createtype.IsArray) { succed = true; value = Activator.CreateInstance(createtype, 0); } else { ClassBinder cb = BindUtils.GetBinder(createtype); succed = true; value = cb.CreateObject(data, Prefix); } } } return(succed); }
private static void LoadConvertByAssembly(Assembly ass) { Type[] types = ass.GetTypes(); for (int i = 0; i < types.Length; i++) { Type type = types[i]; if (type.GetInterface(typeof(IConvert).FullName) != null) { BindUtils.AddConvert(type, Functions.GetTypeAttributes <ConvertAttribute>(type, false)); } } }
public object Parse(NameValueCollection data, string key, string prefix, out bool succeed) { string value = BindUtils.GetValue(data, key, prefix); if (string.IsNullOrEmpty(value)) { succeed = false; } else { succeed = true; } return(value); }
public bool GetValueTypeValue(System.Collections.Specialized.NameValueCollection data, string Prefix, out object value) { IConvert convert = null; value = null; Type createtype = Handler.Property.PropertyType; if (Binder != null && Binder.Convert == null && Binder.Fungible != null) { createtype = Binder.Fungible; } bool succed = false; if (Binder != null && !string.IsNullOrEmpty(Binder.Prefix)) { Prefix = Binder.Prefix; } if (Binder != null) { convert = Binder.GetConvert(); } if (convert == null) { if (BindUtils.Converts.ContainsKey(createtype)) { convert = BindUtils.Converts[createtype]; } } if (convert != null) { value = convert.Parse(data, Handler.Property.Name, Prefix, out succed); } else { if (createtype.IsEnum) { Type tomenutype = typeof(ToEnum <>).MakeGenericType(createtype); convert = (IConvert)Activator.CreateInstance(tomenutype); BindUtils.AddCustomConvert(createtype, convert); object pvalue = convert.Parse(data, Handler.Property.Name, Prefix, out succed); if (succed) { value = Convert.ChangeType(pvalue, createtype); } } } return(succed); }
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); }
public object Parse(NameValueCollection data, string key, string prefix, out bool succeed) { string value = BindUtils.GetValue(data, key, prefix); object result; if (string.IsNullOrEmpty(value)) { succeed = true; result = default(T); } else { IEnumValue enumConvert = BindUtils.GetEnumConvert(typeof(T)); result = enumConvert.GetValue(value, out succeed); } return(result); }
internal static object CreateInstance(Type type, NameValueCollection data, string prefix) { object result; if (BindUtils.Converts.ContainsKey(type)) { IConvert convert = BindUtils.Converts[type]; bool flag; result = convert.Parse(data, null, prefix, out flag); } else { ClassBinder binder = BindUtils.GetBinder(type); result = binder.CreateObject(data, prefix); } return(result); }
private bool GetValueTypeValue(System.Collections.Specialized.NameValueCollection data, string Prefix, out object value) { IConvert convert = null; value = null; Type createtype = Info.ParameterType; if (Binder != null && Binder.Convert == null && Binder.Fungible != null) { createtype = Binder.Fungible; } bool succed = false; if (Binder != null && !string.IsNullOrEmpty(Binder.Prefix)) { Prefix = Binder.Prefix; } if (Binder != null) { convert = Binder.GetConvert(); } if (convert == null) { if (BindUtils.Converts.ContainsKey(createtype)) { convert = BindUtils.Converts[createtype]; } } if (convert != null) { value = convert.Parse(data, Info.Name, Prefix, out succed); } else { if (createtype.IsEnum) { string pvalue = BindUtils.GetValue(data, Info.Name, Prefix); IEnumValue evalue = BindUtils.GetEnumConvert(createtype); value = evalue.GetValue(pvalue, out succed); } } return(succed); }
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); }
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); }
private static void LoadBaseConvert() { Assembly assembly = typeof(BindUtils).Assembly; BindUtils.LoadConvertByAssembly(assembly); }
public static void AddCustomConvert(params Assembly[] assemblies) { BindUtils.AddCustomConvert(assemblies); }
internal static void Full(object obj, NameValueCollection data, string prefix, bool ispostback) { ClassBinder binder = BindUtils.GetBinder(obj.GetType()); binder.FullData(obj, data, prefix, ispostback); }