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); }
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); }
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 static void AddCustomConvert(params Assembly[] assemblies) { BindUtils.AddCustomConvert(assemblies); }