Beispiel #1
0
        public void LoadExample(ExampleAndDesc exAndDesc, DemoBase exBase)
        {
            _exampleBase = exBase;
            this.Text    = exAndDesc.ToString();
            //-------------------------------------------
            //description:
            if (!string.IsNullOrEmpty(exAndDesc.Description))
            {
                TextBox tt = new TextBox();
                tt.Width      = this.flowLayoutPanel1.Width - 5;
                tt.Text       = exAndDesc.Description;
                tt.Multiline  = true;
                tt.ScrollBars = ScrollBars.Vertical;
                tt.Height     = 250;
                tt.BackColor  = Color.Gainsboro;
                tt.Font       = new Font("tahoma", 10);
                this.flowLayoutPanel1.Controls.Add(tt);
            }
            //-------------------------------------------
            _allConfigs.Clear();

            _mainConfigs                    = new ExampleConfigs();
            _mainConfigs._configList        = exAndDesc.GetConfigList();
            _mainConfigs._exampleActionList = exAndDesc.GetActionList();
            _allConfigs.Add(_mainConfigs);

            CreateConfigPresentation(_exampleBase, _mainConfigs, this.flowLayoutPanel1);

            ////--------------------
            var _groupConfigs = exAndDesc.GetGroupConfigList();

            if (_groupConfigs != null)
            {
                int j = _groupConfigs.Count;
                for (int i = 0; i < j; ++i)
                {
                    ExampleGroupConfigDesc groupConfig = _groupConfigs[i];
                    object groupOwner = groupConfig.OwnerProperty.GetGetMethod().Invoke(_exampleBase, null);

                    var subConfig = new ExampleConfigs();

                    subConfig._configList        = groupConfig._configList;
                    subConfig._exampleActionList = groupConfig._configActionList;
                    _allConfigs.Add(subConfig);
                    //
                    Panel subPanel = new Panel();
                    subPanel.Width  = flowLayoutPanel1.Width;
                    subPanel.Height = 300;//example
                    flowLayoutPanel1.Controls.Add(subPanel);

                    CreateConfigPresentation(groupOwner, subConfig, subPanel);
                }
            }
        }
Beispiel #2
0
        bool CreateExampleConfigGroup(DemoConfigAttribute configAttr, System.Reflection.PropertyInfo prop)
        {
            Type configGroup      = prop.PropertyType;
            var  configGroupAttrs = configGroup.GetCustomAttributes(typeof(DemoConfigGroupAttribute), false);

            if (configGroupAttrs.Length > 0)
            {
                //reflection this type
                ExampleGroupConfigDesc groupConfigDesc = new ExampleGroupConfigDesc((DemoConfigGroupAttribute)configGroupAttrs[0], configGroup);
                groupConfigDesc.OwnerProperty = prop;

                List <ExampleConfigDesc> configList   = groupConfigDesc._configList;
                List <ExampleAction>     exActionList = groupConfigDesc._configActionList;
                //
                foreach (var property in configGroup.GetProperties())
                {
                    //1.
                    var foundAttrs = property.GetCustomAttributes(s_demoConfigAttrType, true);
                    if (foundAttrs.Length > 0)
                    {
                        //in this version: no further subgroup
                        configList.Add(new ExampleConfigDesc((DemoConfigAttribute)foundAttrs[0], property));
                    }
                }
                foreach (var met in configGroup.GetMethods())
                {
                    //only public and instance method
                    if (met.IsStatic)
                    {
                        continue;
                    }
                    if (met.DeclaringType == configGroup)
                    {
                        if (met.GetParameters().Length == 0)
                        {
                            var foundAttrs = met.GetCustomAttributes(s_demoAction, false);
                            if (foundAttrs.Length > 0)
                            {
                                //this is configurable attrs
                                exActionList.Add(new ExampleAction((DemoActionAttribute)foundAttrs[0], met));
                            }
                        }
                    }
                }
                //------------
                _groupConfigs.Add(groupConfigDesc);
                return(true);
            }
            return(false);
        }