public int SetObject(IEnumerable objCollection, CellBorderStyle borderStyle) { _borderStyle = borderStyle; Type objType = objCollection.GetType(); if (TypeInterrogator.IsDictionaryType(objType)) { _iter = new Traverser(CollConverter.ToList(objCollection, GenBuilder.BuildKeyValueType(objType))); } else { _iter = new Traverser(CollConverter.ToList(objCollection)); } _objControl.SetObject(_iter.First, null, _borderStyle); return(0); }
public object ToPropertyValue(object cv) { return((object)(CollConverter.ToList((IEnumerable)cv, _itemType))); }
private void BuildCollectionCtrl(PropertyInfo pi, Type tp, object parentObj, ObjIdentifier parentId) { PropertyCtrlInfo ci = BuildControlInfo(pi, parentObj); Page page = (ci.Layout.IsAdvanced) ? Macros.SafeGet(ref _advancedPage) : _mainPage; object piValue = (parentObj == null) ? null : pi.GetValue(parentObj, null); Type itemT = TypeInterrogator.GetItemType(tp); if (TypeInterrogator.IsSingleValueType(itemT)) { if (TypeInterrogator.IsEnumType(itemT)) { BitFlagsPCV converter = new BitFlagsPCV(itemT); ci.Binder = new CheckedListBoxBinder(converter.ToControlValue(itemT), converter.ToControlValue((IEnumerable)piValue)); ci.Converter = converter; } else if (TypeInterrogator.IsStringType(itemT)) { if (TypeInterrogator.IsArrayType(tp)) { ci.Converter = new ArrayPCV(itemT); } else if (TypeInterrogator.IsListType(tp)) { ci.Converter = new ListPCV(itemT); } if (_objHints.ValueHints != null && _objHints.ValueHints.ContainsKey(pi.Name)) { ci.Binder = new ListBoxBinder(_objHints.ValueHints[pi.Name], (IEnumerable <string>)piValue); } else { ci.Binder = new ListBoxBinder((IEnumerable <string>)piValue); } } else if (TypeInterrogator.IsNumericType(itemT)) { if (TypeInterrogator.IsArrayType(tp)) { ci.Converter = new ArrayPCV(itemT); } else if (TypeInterrogator.IsListType(tp)) { ci.Converter = new ListPCV(itemT); } if (_objHints.ValueHints != null && _objHints.ValueHints.ContainsKey(pi.Name)) { ci.Binder = new ListBoxBinder(_objHints.ValueHints[pi.Name], CollConverter.ToStringArray((IEnumerable)piValue)); } else { ci.Binder = new ListBoxBinder(CollConverter.ToStringArray((IEnumerable)piValue)); } } else { Debug.Assert(false); } } else { ci.Binder = new ObjCollectionBinder((IEnumerable)piValue, null); } AddControlInfo(page, ci, parentId); }
private void BuildLeafCtrl(PropertyInfo pi, Type tp, object parentObj, ObjIdentifier parentId) { PropertyCtrlInfo ci = BuildControlInfo(pi, parentObj); Page page = (ci.Layout.IsAdvanced) ? Macros.SafeGet(ref _advancedPage) : _mainPage; object piValue = (parentObj == null) ? null : pi.GetValue(parentObj, null); if (TypeInterrogator.IsNumericType(tp)) { DecimalPCV converter = new DecimalPCV(tp); ci.Converter = converter; NumericUpDownHint upDownHint = AttributeInterrogator.GetAttribute <NumericUpDownHint>(pi); if (upDownHint != null) { ci.Binder = new NumericUpDownSingleBinder((piValue == null) ? Decimal.MinValue : Decimal.Parse(piValue.ToString()), upDownHint); } else { TextBoxHint tbHint = AttributeInterrogator.GetAttribute <TextBoxHint>(pi); if (tbHint == null) { tbHint = new TextBoxHint(); } tbHint.CharsAccepted = TextBoxHint.Numbers; ci.Binder = new TextBoxBinder((piValue == null) ? null : piValue.ToString(), tbHint); } } else if (TypeInterrogator.IsBoolType(tp)) { ci.Binder = new CheckBoxBinder(ci.Layout.Label, (piValue == null) ? false : (bool)piValue); ci.Layout.Label = null; ci.Layout.Section = Section.Footer; } else if (TypeInterrogator.IsDateTimeType(tp)) { ci.Binder = new DateTimePickerBinder((piValue == null) ? DateTime.Today : (DateTime)piValue, null); } else if (TypeInterrogator.IsEnumType(tp)) { const int MaxRadioButtonCount = 3; IEnumerable <string> names = EnumConverter.ToNames(tp, true); if (CollConverter.GetCount(names) <= MaxRadioButtonCount) { ci.Binder = new RadioButtonBinder(tp, (piValue == null) ? -1 : (int)piValue); } else { EnumPCV converter = new EnumPCV(tp); ci.Binder = new ComboBoxBinder(piValue.ToString(), names, ComboBoxStyle.DropDownList); ci.Converter = converter; } } else if (TypeInterrogator.IsStringType(tp)) { if (_objHints.ValueHints != null && _objHints.ValueHints.ContainsKey(pi.Name)) { ci.Binder = new ComboBoxBinder((piValue == null) ? null : piValue.ToString(), _objHints.ValueHints[pi.Name], ComboBoxStyle.DropDown); } else { LayoutHint lhint = AttributeInterrogator.GetAttribute <LayoutHint>(pi); ci.Binder = new TextBoxBinder((piValue == null) ? null : piValue.ToString(), lhint); } } else if (tp == typeof(System.Data.DataTable)) { ci.Binder = new DataGridViewBinder((piValue == null) ? null : piValue as System.Data.DataTable); ci.Layout.ColumnCount = 2; } else if (TypeInterrogator.IsDictionaryType(tp)) { DictionaryPCV converter = new DictionaryPCV(); Dictionary <string, string> converted = (piValue == null) ? null : converter.ToControlValue(piValue); ci.Binder = new DictionaryCtrlBinder(converted, _objHints.DictionaryHint); ci.Converter = converter; ci.Layout.Label = null; ci.Layout.ColumnCount = 2; ci.Layout.RowCount = (converted != null) ? (int)((converted.Count + 1) * 1.5) : 2; } AddControlInfo(page, ci, parentId); }