private static void RegisterCommandGroups() { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly asm in assemblies) { foreach (Type type in asm.GetTypes()) { if (!type.IsSubclassOf(typeof(CommandGroup))) { continue; } CommandGroupAttribute[] attributes = (CommandGroupAttribute[])type.GetCustomAttributes(typeof(CommandGroupAttribute), true); if (attributes.Length == 0) { continue; } CommandGroupAttribute groupAttribute = attributes[0]; CommandGroup group = (CommandGroup)Activator.CreateInstance(type); group.Register(groupAttribute); CommandGroups.Add(groupAttribute, group); } } }
public bool RegisterType(Type type) { if (!type.IsSubclassOf(typeof(CommandGroup))) { return(false); } CommandGroupAttribute[] attributes = (CommandGroupAttribute[])type.GetCustomAttributes(typeof(CommandGroupAttribute), true); if (attributes.Length == 0) { return(false); } CommandGroupAttribute groupAttribute = attributes[0]; CommandGroup commandGroup = (CommandGroup)Activator.CreateInstance(type); commandGroup.Register(groupAttribute); return(RegisterCommandGroup(groupAttribute.Name, commandGroup)); }
public void Register(CommandGroupAttribute attributes) { Attributes = attributes; RegisterDefaultCommand(); RegisterCommands(); }