Ejemplo n.º 1
0
        public static Category Create(Type type)
        {
            CategoryAttribute attribute = type.GetCategoryAttribute();

            if (attribute == null)
            {
                return(null);
            }

            Category       category = new Category(attribute.name);
            List <Command> commands = Library.Commands;

            foreach (Command command in commands)
            {
                if (command.Owner == type)
                {
                    category.commands.Add(command);
                }
            }

            return(category);
        }
Ejemplo n.º 2
0
        public static CategoryAttribute GetCategoryAttribute(this Type type)
        {
            try
            {
                CategoryAttribute attribute  = null;
                object[]          attributes = type.GetCustomAttributes(typeof(CategoryAttribute), false);
                for (int a = 0; a < attributes.Length; a++)
                {
                    if (attributes[a].GetType() == typeof(CategoryAttribute))
                    {
                        attribute = attributes[a] as CategoryAttribute;
                        return(attribute);
                    }
                }
            }
            catch
            {
                //this could happen due to a TypeLoadException in builds
            }

            return(null);
        }