コード例 #1
0
    public T GetValueOrDefault <T>(this IXAttribute attr)
    {
        var typedAttr = attr as IXAttribute <T>;

        if (typedAttr == null)
        {
            return(default(T));
        }
        return(typedAttr.Value);
    }
コード例 #2
0
        /// <summary>
        /// Creates Label control from given IXAttribute.
        /// </summary>
        /// <param name="attribute">Given IXAttribute.</param>
        /// <returns>Label control according to given IXAttribute.</returns>
        internal Label GetLabel(IXAttribute attribute)
        {
            var label = new Label();

            label.AutoSize = true;
            label.Name     = attribute.Name + "Label";
            label.Size     = new Size(35, 13);
            label.TabIndex = 0;
            label.Text     = attribute.Name.ToReadable();
            return(label);
        }
コード例 #3
0
        /// <summary>
        /// Creates Control control from given IXAttribute.
        /// </summary>
        /// <param name="attribute">Given IXAttribute.</param>
        /// <returns>Label control according to given IXAttribute.</returns>
        internal Control GetControl(IXAttribute attribute)
        {
            var control = new Control();

            if (attribute is XAttribute <string> )
            {
                var stringAttribute = (XAttribute <string>)attribute;
                var textBox         = new TextBox();
                control = textBox;
                control.DataBindings.Add("Text", stringAttribute, "Value");
            }
            else if (attribute is XAttribute <int> )
            {
                var intAttribute  = (XAttribute <int>)attribute;
                var numericUpDown = new NumericUpDown();
                numericUpDown.DataBindings.Add("Value", intAttribute, "Value");
                control = numericUpDown;
            }
            else if (attribute is XAttribute <bool> )
            {
                var boolAttribute = (XAttribute <bool>)attribute;
                var checkBox      = new CheckBox();
                control = checkBox;
                checkBox.DataBindings.Add("Checked", boolAttribute, "Value");
            }
            else if (attribute is XAttribute <DateTime> )
            {
                var dateTimeAttribute = (XAttribute <DateTime>)attribute;
                var dateTimePicker    = new DateTimePicker();

                if (!dateTimeAttribute.Value.HasMeaning())
                {
                    dateTimeAttribute.Value = DateTime.Now;
                }

                dateTimePicker.DataBindings.Add("Value", dateTimeAttribute, "Value");
                control = dateTimePicker;
            }
            else if (attribute is XEnumerationAttribute <string> )
            {
                var enumerationAttribute = (XEnumerationAttribute <string>)attribute;
                var enumeration          = enumerationAttribute.Enumeration;

                var comboBox = new ComboBox();

                comboBox.BeginUpdate();
                comboBox.Items.Clear();
                foreach (var item in enumeration)
                {
                    comboBox.Items.Add(item);
                }
                comboBox.EndUpdate();

                comboBox.SelectedItem = enumerationAttribute.Value;
                comboBox.DataBindings.Add("Text", enumerationAttribute, "Value");
                control = comboBox;
            }

            control.Name = attribute.Name;
            control.Tag  = attribute;


            return(control);
        }
コード例 #4
0
        /// <summary>
        /// Creates Control control from given IXAttribute.
        /// </summary>
        /// <param name="attribute">Given IXAttribute.</param>
        /// <returns>Label control according to given IXAttribute.</returns>
        internal Control GetControl(IXAttribute attribute)
        {
            var control = new Control();

            if (attribute is XAttribute<string>)
            {
                var stringAttribute = (XAttribute<string>)attribute;
                var textBox = new TextBox();
                control = textBox;
                control.DataBindings.Add("Text", stringAttribute, "Value");
            }
            else if (attribute is XAttribute<int>)
            {
                var intAttribute = (XAttribute<int>)attribute;
                var numericUpDown = new NumericUpDown();
                numericUpDown.DataBindings.Add("Value", intAttribute, "Value");
                control = numericUpDown;
            }
            else if (attribute is XAttribute<bool>)
            {
                var boolAttribute = (XAttribute<bool>)attribute;
                var checkBox = new CheckBox();
                control = checkBox;
                checkBox.DataBindings.Add("Checked", boolAttribute, "Value");
            }
            else if (attribute is XAttribute<DateTime>)
            {
                var dateTimeAttribute = (XAttribute<DateTime>)attribute;
                var dateTimePicker = new DateTimePicker();

                if (!dateTimeAttribute.Value.HasMeaning())
                {
                    dateTimeAttribute.Value = DateTime.Now;
                }

                dateTimePicker.DataBindings.Add("Value", dateTimeAttribute, "Value");
                control = dateTimePicker;
            }
            else if (attribute is XEnumerationAttribute<string>)
            {
                var enumerationAttribute = (XEnumerationAttribute<string>)attribute;
                var enumeration = enumerationAttribute.Enumeration;

                var comboBox = new ComboBox();

                comboBox.BeginUpdate();
                comboBox.Items.Clear();
                foreach (var item in enumeration)
                {
                    comboBox.Items.Add(item);
                }
                comboBox.EndUpdate();

                comboBox.SelectedItem = enumerationAttribute.Value;
                comboBox.DataBindings.Add("Text", enumerationAttribute, "Value");
                control = comboBox;
            }

            control.Name = attribute.Name;
            control.Tag = attribute;

            return control;
        }
コード例 #5
0
 /// <summary>
 /// Creates Label control from given IXAttribute.
 /// </summary>
 /// <param name="attribute">Given IXAttribute.</param>
 /// <returns>Label control according to given IXAttribute.</returns>
 internal Label GetLabel(IXAttribute attribute)
 {
     var label = new Label();
     label.AutoSize = true;
     label.Name = attribute.Name + "Label";
     label.Size = new Size(35, 13);
     label.TabIndex = 0;
     label.Text = attribute.Name;
     return label;
 }