예제 #1
0
        private IEnumerable<object> GetLookupValues(PropertyInfo prop, IAfterglowPlugin plugin, ConfigLookupAttribute configAttribute)
        {
            Type pluginType = plugin.GetType();
            Type propertyType = prop.PropertyType;

            string displayName = configAttribute.DisplayName;
            IEnumerable<object> availableValues = null;
            if (propertyType.IsEnum)
            {
                availableValues = propertyType.GetEnumNames() as IEnumerable<object>;
            }
            else if (configAttribute.RetrieveValuesFrom != null)
            {
                var member = pluginType.GetMember(configAttribute.RetrieveValuesFrom);
                if (member.Length > 0)
                {
                    if (member[0].MemberType == MemberTypes.Property)
                    {
                        PropertyInfo pi = pluginType.GetProperty(configAttribute.RetrieveValuesFrom);

                        var propertyValue = pi.GetValue(plugin, null);
                        if (typeof(IEnumerable<>).MakeGenericType(propertyType).IsAssignableFrom(propertyValue.GetType()))
                        {
                            availableValues = propertyValue as IEnumerable<object>;
                        }
                        else
                        {
                            throw new ArgumentException("incorrect type", "RetrieveValuesFrom");
                        }

                    }
                    else if (member[0].MemberType == MemberTypes.Method)
                    {
                        MethodInfo mi = pluginType.GetMethod(configAttribute.RetrieveValuesFrom);

                        var propertyValue = mi.Invoke(plugin, null);
                        if (typeof(IEnumerable<>).MakeGenericType(propertyType).IsAssignableFrom(propertyValue.GetType()))
                        {
                            availableValues = propertyValue as IEnumerable<object>;
                        }
                        else
                        {
                            throw new ArgumentException("incorrect type", "RetrieveValuesFrom");
                        }
                    }
                }
            }
            return availableValues;
        }
예제 #2
0
        private IEnumerable <object> GetLookupValues(PropertyInfo prop, IAfterglowPlugin plugin, ConfigLookupAttribute configAttribute)
        {
            Type pluginType   = plugin.GetType();
            Type propertyType = prop.PropertyType;

            string displayName = configAttribute.DisplayName;
            IEnumerable <object> availableValues = null;

            if (propertyType.IsEnum)
            {
                availableValues = propertyType.GetEnumNames() as IEnumerable <object>;
            }
            else if (configAttribute.RetrieveValuesFrom != null)
            {
                var member = pluginType.GetMember(configAttribute.RetrieveValuesFrom);
                if (member.Length > 0)
                {
                    if (member[0].MemberType == MemberTypes.Property)
                    {
                        PropertyInfo pi = pluginType.GetProperty(configAttribute.RetrieveValuesFrom);

                        var propertyValue = pi.GetValue(plugin, null);
                        if (typeof(IEnumerable <>).MakeGenericType(propertyType).IsAssignableFrom(propertyValue.GetType()))
                        {
                            availableValues = propertyValue as IEnumerable <object>;
                        }
                        else
                        {
                            throw new ArgumentException("incorrect type", "RetrieveValuesFrom");
                        }
                    }
                    else if (member[0].MemberType == MemberTypes.Method)
                    {
                        MethodInfo mi = pluginType.GetMethod(configAttribute.RetrieveValuesFrom);

                        var propertyValue = mi.Invoke(plugin, null);
                        if (typeof(IEnumerable <>).MakeGenericType(propertyType).IsAssignableFrom(propertyValue.GetType()))
                        {
                            availableValues = propertyValue as IEnumerable <object>;
                        }
                        else
                        {
                            throw new ArgumentException("incorrect type", "RetrieveValuesFrom");
                        }
                    }
                    else if (member[0].MemberType == MemberTypes.Field)
                    {
                        FieldInfo fi = pluginType.GetField(configAttribute.RetrieveValuesFrom);

                        var propertyValue = fi.GetValue(plugin);
                        if (typeof(System.Collections.ObjectModel.ObservableCollection <string>) == propertyValue.GetType())
                        {
                            availableValues     = propertyValue as IEnumerable <object>;
                            _useCollectionIndex = true;
                        }
                        else
                        {
                            throw new ArgumentException("incorrect type", "RetrieveValuesFrom");
                        }
                    }
                }
            }
            return(availableValues);
        }
예제 #3
0
        private void AutoGenPluginUserControlLoad(object sender, EventArgs e)
        {
            this.Controls.Clear();

            Type t = _plugin.GetType();

            List <BaseControl> controls = new List <BaseControl>();

            foreach (PropertyInfo prop in t.GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                if (Attribute.IsDefined(prop, typeof(ConfigAttribute)) &&
                    !(Attribute.GetCustomAttribute(prop, typeof(ConfigAttribute)) as ConfigAttribute).IsHidden)
                {
                    if (Attribute.IsDefined(prop, typeof(ConfigLookupAttribute)))
                    {
                        controls.Add(new LookupControl(prop, _plugin));
                    }
                    else if (Attribute.IsDefined(prop, typeof(ConfigNumberAttribute)))
                    {
                        controls.Add(new NumberControl(prop, _plugin));
                    }
                    else if (Attribute.IsDefined(prop, typeof(ConfigStringAttribute)))
                    {
                        controls.Add(new StringControl(prop, _plugin));
                    }
                    else if (Attribute.IsDefined(prop, typeof(ConfigReadOnlyAttribute)))
                    {
                        controls.Add(new ReadOnlyControl(prop, _plugin));
                    }
                }
            }
            ConfigCustomAttribute configCustom = (ConfigCustomAttribute)Attribute.GetCustomAttribute(t, typeof(ConfigCustomAttribute));

            if (configCustom != null)
            {
                BaseControl control = CreateCustomControl(configCustom);

                control.Parent = this;
                control.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;

                controls.Add(control);
            }

            //Add Sort to not set values
            foreach (var item in controls.Where(s => s.SortIndex == 0))
            {
                item.SortIndex = (from c in controls
                                  orderby c.SortIndex descending
                                  select c.SortIndex).FirstOrDefault() + 100;
            }

            //Sort controls
            controls = (from c in controls
                        orderby c.SortIndex
                        select c).ToList();

            //Add Controls
            controls.ForEach(c => AddControl(c));

            //TODO add scroll bar control may not need it
        }