protected virtual void SetTypeParameter()
        {
            if (typeSelectorDialog == null)
            {
                typeSelectorDialog         = new TypeSelectorDialog();
                typeSelectorDialog.Caption = "Select Type of Generic Type Parameter";
            }
            Type param = typeParametersListView.SelectedItems[0].Tag as Type;

            Type[] constraints = param.GetGenericParameterConstraints();
            bool   showNotInstantiableTypes = !param.GenericParameterAttributes.HasFlag(GenericParameterAttributes.DefaultConstructorConstraint);

            typeSelectorDialog.TypeSelector.Configure(constraints, showNotInstantiableTypes, true, true);

            if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK)
            {
                Type   selected   = typeSelectorDialog.TypeSelector.SelectedType;
                Type[] parameters = SelectedType.GetGenericArguments();
                parameters[param.GenericParameterPosition] = selected;
                SelectedType = SelectedType.GetGenericTypeDefinition().MakeGenericType(parameters);

                typeParametersListView.SelectedItems[0].Text = param.Name + ": " + selected.GetPrettyName();
                typeParametersListView.Columns[0].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
            }
        }
 protected virtual void setValueButton_Click(object sender, EventArgs e)
 {
     if (typeSelectorDialog == null)
     {
         typeSelectorDialog         = new TypeSelectorDialog();
         typeSelectorDialog.Caption = "Select Value";
         typeSelectorDialog.TypeSelector.Configure(typeof(IItem), false, true);
     }
     if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK)
     {
         try {
             Content.Value = (IItem)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
         }
         catch (Exception ex) {
             ErrorHandling.ShowErrorDialog(this, ex);
         }
     }
 }
        protected virtual T CreateItem()
        {
            if (typeSelectorDialog == null)
            {
                typeSelectorDialog         = new TypeSelectorDialog();
                typeSelectorDialog.Caption = "Select Item";
                typeSelectorDialog.TypeSelector.Caption = "Available Items";
                typeSelectorDialog.TypeSelector.Configure(typeof(T), false, true);
            }

            if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK)
            {
                try {
                    return((T)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType());
                } catch (Exception ex) {
                    ErrorHandling.ShowErrorDialog(this, ex);
                }
            }
            return(null);
        }
Exemple #4
0
        private void addButton_Click(object sender, EventArgs e)
        {
            if (typeSelectorDialog == null)
            {
                typeSelectorDialog         = new TypeSelectorDialog();
                typeSelectorDialog.Caption = "Select Item";
                typeSelectorDialog.TypeSelector.Caption = "Available Items";
                typeSelectorDialog.TypeSelector.Configure(typeof(T), false, true);
            }

            if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK)
            {
                try {
                    AddItem((T)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType());
                }
                catch (Exception ex) {
                    ErrorHandling.ShowErrorDialog(this, ex);
                }
            }
        }