Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public ExampleConfigDesc(DemoConfigAttribute config, System.Reflection.PropertyInfo property)
        {
            this.property = property;
            this.OriginalConfigAttribute = config;
            if (!string.IsNullOrEmpty(config.Name))
            {
                this.Name = config.Name;
            }
            else
            {
                this.Name = property.Name;
            }


            Type propType = property.PropertyType;

            if (propType == typeof(bool))
            {
                this.PresentaionHint = DemoConfigPresentaionHint.CheckBox;
            }
            else if (propType.IsEnum)
            {
                this.PresentaionHint = Mini.DemoConfigPresentaionHint.OptionBoxes;
                //find option
                var enumFields = propType.GetFields();

                int j = enumFields.Length;
                optionFields = new List <ExampleConfigValue>(j);
                for (int i = 0; i < j; ++i)
                {
                    var enumField = enumFields[i];
                    if (enumField.IsStatic)
                    {
                        //use field name or note that assoc with its field name

                        string fieldNameOrNote = enumField.Name;
                        var    foundNotAttr    = enumField.GetCustomAttributes(typeof(NoteAttribute), false);
                        if (foundNotAttr.Length > 0)
                        {
                            fieldNameOrNote = ((NoteAttribute)foundNotAttr[0]).Desc;
                        }
                        optionFields.Add(new ExampleConfigValue(property, enumField, fieldNameOrNote));
                    }
                }
            }
            else if (propType == typeof(Int32))
            {
                this.PresentaionHint = Mini.DemoConfigPresentaionHint.SlideBarDiscrete;
            }
            else if (propType == typeof(double))
            {
                this.PresentaionHint = Mini.DemoConfigPresentaionHint.SlideBarContinuous_R8;
            }
            else if (propType == typeof(float))
            {
                this.PresentaionHint = Mini.DemoConfigPresentaionHint.SlideBarContinuous_R4;
            }
            else
            {
                this.PresentaionHint = DemoConfigPresentaionHint.TextBox;
            }
        }