Пример #1
0
        /// <summary>
        /// Return true if any of the following conditions is satisfied:
        ///   1. Property is Delegate / Event
        ///   2. Can not read or write
        ///   3. Marked with XmlIgnore
        /// </summary>
        private bool IsSkipped(PropertyInfo pi, Type tp)
        {
            if (TypeInterrogator.IsDelegateType(tp) || TypeInterrogator.IsEventType(tp))
            {
                return(true);
            }

            if (!pi.CanRead || !pi.CanWrite) // skip readonly properties. may revisit this
            {
                return(true);
            }

            System.ComponentModel.BrowsableAttribute brw = AttributeInterrogator.GetAttribute <System.ComponentModel.BrowsableAttribute>(pi);
            if (brw != null && !brw.Browsable)
            {
                return(true);
            }

            return(false);
        }
Пример #2
0
        private PropertyCtrlInfo BuildControlInfo(PropertyInfo pi, object parentObj)
        {
            PropertyCtrlInfo ci = new PropertyCtrlInfo();

            ci.PropertyInfo = pi;
            ci.ParentObject = parentObj;

            ci.Layout = AttributeInterrogator.GetAttribute <LayoutHint>(pi);
            if (ci.Layout == null)
            {
                ci.Layout = new LayoutHint();
            }

            if (_objHints.LabelHints != null && _objHints.LabelHints.ContainsKey(pi.Name))
            {
                ci.Layout.Label = _objHints.LabelHints[pi.Name];
            }
            if (string.IsNullOrEmpty(ci.Layout.Label))
            {
                ci.Layout.Label = NameCleaner.ToPhrase(pi.Name);
            }

            return(ci);
        }
Пример #3
0
        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);
        }