コード例 #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            //System.Collections.CollectionBase
            //new ComboBoxItem().Value
            //new CheckedListBoxItem().Description
            //new RadioGroupItem().Description

            //checkedComboBoxEdit1.Properties.Items;
            //radioGroup1.Properties.Items;
            //comboBoxEdit1;
            //imageComboBoxEdit1;
            //comboBoxEdit1.Properties.Items
            //Thread aaa = new Thread();

            Dictionary <string, string> lista1 = new Dictionary <string, string>();

            this.Controls
            .OfType <Control>()
            .ToList()
            .ForEach(itemControle =>
            {
                MethodInfo memberInfo = itemControle.GetType().GetMethod("get_Properties");

                //Type tipo = itemControle.GetType();
                //var x1 = tipo.InvokeMember("Properties", BindingFlags.GetProperty | BindingFlags.GetField, null, itemControle, null);
                //if (x1 == null)
                //{

                //}

                if (memberInfo != null)
                {
                    object getProperties = memberInfo.Invoke(itemControle, null);
                    memberInfo           = getProperties.GetType().GetMethod("get_Items");

                    CollectionBase itensProperties = null;
                    if (memberInfo != null)
                    {
                        itensProperties = memberInfo.Invoke(getProperties, null) as System.Collections.CollectionBase;
                    }

                    if (itensProperties != null)
                    {
                        itensProperties
                        .OfType <object>()
                        .Select((s, index) => new
                        {
                            Item  = s,
                            Index = index
                        })
                        .ToList()
                        .ForEach(itemProperties =>
                        {
                            string valorItem = String.Empty;
                            if (itemProperties.Item.GetType().GetProperty("Description") == null)
                            {
                                valorItem = itemProperties.Item.ToString();
                            }
                            else
                            {
                                valorItem = itemProperties.Item.GetType().GetMethod("get_Description").Invoke(itemProperties.Item, null).ToString();
                            }

                            lista1.Add(String.Concat(itemControle.Name, ".", itemProperties.Index), valorItem);
                        });
                    }
                }
            });

            if (lista1 == null)
            {
            }
        }