public static IDictionary <string, object> ToDictionary(this object value) { if (value == null) { return(null); } IDictionary <string, object> dictionary = null; if (typeof(IDictionary <string, object>).IsAssignableFrom(value.GetType())) { dictionary = value as IDictionary <string, object>; } else if (value.GetType().IsSubclassOf(typeof(NameValueCollection))) { var data = value as NameValueCollection; dictionary = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase); foreach (var key in data.AllKeys) { dictionary.Add(key, data[key]); } } else { dictionary = new FoxOneDictionary <string, object>(StringComparer.OrdinalIgnoreCase); if (value is IExtProperty) { var prop = (value as IExtProperty).Properties; if (!prop.IsNullOrEmpty()) { dictionary.AddRange(prop); } } FastType fastType = FastType.Get(value.GetType()); fastType.Getters.ForEach(getter => { if (getter.Type.IsArray || getter.Type.IsValueType || getter.Type == typeof(string)) { string name = getter.Name; if (!name.IsNullOrEmpty()) { object val = getter.GetValue(value); dictionary.Add(name, val); } } }); } return(dictionary); }
public void SetTarget(IList <IControl> components) { if (!Fields.IsNullOrEmpty()) { var formData = new FoxOneDictionary <string, object>(StringComparer.OrdinalIgnoreCase); string key = string.Empty; var request = HttpContext.Current.Request; foreach (var f in Fields) { if (f is TimeRangePicker) { //日期范围控件特殊处理 var dt = f as TimeRangePicker; if (!dt.DefaultStartValue.IsNullOrEmpty()) { formData.Add(NamingCenter.GetTimeRangeDatePickerStartId(dt.Name), DateTime.Parse(Env.Parse(dt.DefaultStartValue)).ToString(dt.DateTimeFormat)); } if (!dt.DefaultEndValue.IsNullOrEmpty()) { formData.Add(NamingCenter.GetTimeRangeDatePickerEndId(dt.Name), DateTime.Parse(Env.Parse(dt.DefaultEndValue)).ToString(dt.DateTimeFormat)); } } else if (f is DatePicker) { if (!f.Value.IsNullOrEmpty()) { key = f.Name.IsNullOrEmpty() ? f.Id : f.Name; var d = f as DatePicker; formData.Add(key, DateTime.Parse(Env.Parse(f.Value)).ToString(d.DateTimeFormat)); } } else { if (!f.Value.IsNullOrEmpty()) { key = f.Name.IsNullOrEmpty() ? f.Id : f.Name; if (!request.Form.AllKeys.Contains(key) && !request.QueryString.AllKeys.Contains(key)) { formData.Add(key, Env.Parse(f.Value)); } } } } foreach (var c in components) { if (c is IListDataSourceControl) { var ds = (c as IListDataSourceControl).DataSource; if (ds != null) { if (ds.Parameter == null) { ds.Parameter = formData; } else { var dict = ds.Parameter as Dictionary <string, object>; foreach (var f in formData.Keys) { dict[f] = formData[f]; } } } } } } }