Exemplo n.º 1
0
 private void populateItems(Reflection.PropertyData[] items)
 {
     foreach (Reflection.PropertyData item in items)
     {
         if (ddTemplateName.Items.FindByText(item.ClassDesc) != null) continue;
         ddTemplateName.Items.Add(new ListItem(item.ClassDesc, item.ID.Split('+')[0] + "+" + item.ClassDesc));
     }
 }
Exemplo n.º 2
0
        private Control CreateControl(Reflection.PropertyData item)
        {
            //Creating control from its type
            Control control;
            //if control type is specified create it
            if (item.ControlType != null)
            {
                try
                {
                    control = (Control)Activator.CreateInstance(item.ControlType, null);
                }
                catch (InvalidCastException)
                {
                    throw new InvalidCastException(
                        String.Format(
                            "The ControlAttribute for property named {0} must specify descedant of System.Web.UI.Control class",
                            item.PropertyName));
                }

                //applying the value of the control
                control.GetType().GetProperty(item.ControlProperty).SetValue(control, item.Value, null);
            }
            else //otherwise create TextBox
            {
                control = new TextBox();
                (control as TextBox).Text = item.Value.ToString();
            }

            Hashtable propertiesToApply = item.PropertiesToApply;
            foreach (object key in propertiesToApply.Keys)
            {
                PropertyInfo propertyInfo = control.GetType().GetProperty((string)key);
                object _value = propertiesToApply[key];

                try
                {
                    if (propertyInfo.GetValue(control, null).GetType() == typeof(Unit))
                    {
                        if (_value is String)
                            _value = new Unit((string)_value);
                        else if (_value is Int32)
                            _value = new Unit((int)_value);
                        else if (_value is Double)
                            _value = new Unit((double)_value);
                    }

                    propertyInfo.SetValue(control, _value, null);
                }
                catch
                {
                    throw new Exception(String.Format("Invalid Property/Value pair ({0} / {1}) for control of type {2}",
                                                      key.ToString(), propertiesToApply[key],
                                                      control.GetType().ToString()));
                }
            }

            control.ID = item.ID.Replace('+', '_');
            control.EnableViewState = false;
            return control;
        }