コード例 #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);
            }
        }
コード例 #2
0
        private void OnMethodsListViewItemChecked(object sender, ItemCheckedEventArgs e)
        {
            MethodListViewItem listViewItem = (MethodListViewItem)e.Item;

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