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); }
public static Category Create(Type type) { CategoryAttribute attribute = type.GetCategoryAttribute(); if (attribute == null) { return(null); } Category category = new Category(attribute.name); List <ConsoleCommand> commands = Library.Commands; foreach (ConsoleCommand command in commands) { if (command.Owner == type) { category.commands.Add(command); } } return(category); }