Esempio n. 1
0
        public WrappingOptions(WrappedType wrappedType)
        {
            InitializeComponent();
            InitializeWrapper();

            this.wrappedType = wrappedType;

            Tuple[] acquisitionModes =
            {
                new Tuple(Acquisition.Construct,   "Construct an instance of the wrapped type"),
                new Tuple(Acquisition.Parameter,   "Pass an instance of the wrapped type as a parameter"),
                new Tuple(Acquisition.Property,    "Set an instance of the wrapped type as a property"),
                new Tuple(Acquisition.UserManaged, "Allow user to control instance management of the wrapped type")
            };

            this.acquisitionComboBox.ValueMember   = "Value1";
            this.acquisitionComboBox.DisplayMember = "Values";
            this.acquisitionComboBox.Items.AddRange(acquisitionModes);
            this.acquisitionComboBox.SelectedIndex = 0;

            this.defaultFieldName      = wrappedType.FieldName;
            this.fieldNameTextBox.Text = this.defaultFieldName;

            // Methods
            MethodInfo[] methods = wrappedType.Type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
            Array.Sort <MethodInfo> (methods, this.MethodNameComparison);
            foreach (MethodInfo method in methods)
            {
                if (!method.Name.ToLower().StartsWith("get_") && !method.Name.ToLower().StartsWith("set_") &&
                    !method.Name.ToLower().StartsWith("add_") && !method.Name.ToLower().StartsWith("remove_"))
                {
                    MethodListViewItem listViewItem = new MethodListViewItem(method);
                    listViewItem.ImageIndex = (int)WrappingOptions.ImageIndices.Method;
                    this.methodsListView.Items.Add(listViewItem);
                }
            }

            // Properties
            PropertyInfo[] properties = wrappedType.Type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
            Array.Sort <PropertyInfo> (properties, this.PropertyNameComparison);
            foreach (PropertyInfo property in properties)
            {
                PropertyListViewItem listViewItem = new PropertyListViewItem(property);
                listViewItem.ImageIndex = (int)WrappingOptions.ImageIndices.Property;
                this.propertiesListView.Items.Add(listViewItem);
            }

            // Events
            EventInfo[] events = wrappedType.Type.GetEvents(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
            Array.Sort <EventInfo> (events, this.EventNameComparison);
            foreach (EventInfo _event in events)
            {
                EventListViewItem listViewItem = new EventListViewItem(_event);
                listViewItem.ImageIndex = (int)WrappingOptions.ImageIndices.Event;
                this.eventsListView.Items.Add(listViewItem);
            }
        }
Esempio n. 2
0
        private void OnEventsListViewItemChecked(object sender, ItemCheckedEventArgs e)
        {
            EventListViewItem listViewItem = (EventListViewItem)e.Item;

            if (e.Item.Checked)
            {
                this.wrappedType.WrappedEvents.Add(listViewItem.WrappedEvent);
            }
            else
            {
                this.wrappedType.WrappedEvents.Remove(listViewItem.WrappedEvent);
            }
        }