Пример #1
0
        private void setComboBoxOptions()
        {
            Type type = this.GetType();
            IEnumerable <MethodInfo> info = type.GetRuntimeMethods();

            foreach (MethodInfo method in info)
            {
                Object[] attr = method.GetCustomAttributes(true);
                foreach (var att in attr)
                {
                    if (att is SortingAttribute)
                    {
                        SortingAttribute s = att as SortingAttribute;
                        comboBoxSort.Invoke(new Action(() => comboBoxSort.Items.Add(s)));
                    }
                }
            }
        }
Пример #2
0
        private void ComboBoxSort_SelectedIndexChanged(object sender, EventArgs e)
        {
            SortingAttribute t = comboBoxSort.SelectedItem as SortingAttribute;

            Type type = this.GetType();
            IEnumerable <MethodInfo> info = type.GetRuntimeMethods();

            foreach (MethodInfo method in info)
            {
                Object[] attr = method.GetCustomAttributes(true);
                foreach (var k in attr)
                {
                    if (k is SortingAttribute)
                    {
                        SortingAttribute s = k as SortingAttribute;
                        if (t.Name == s.Name)
                        {
                            method.Invoke(this, null);
                        }
                    }
                }
            }
        }