示例#1
0
        public ChatCommand(Type type, CommandAttribute attribute)
        {
            Name         = attribute.Name;
            Permission   = attribute.RBAC;
            AllowConsole = attribute.AllowConsole;
            Help         = attribute.Help;

            foreach (var method in type.GetMethods(BindingFlags.Static | BindingFlags.NonPublic))
            {
                CommandAttribute commandAttribute = method.GetCustomAttribute <CommandAttribute>(false);
                if (commandAttribute == null)
                {
                    continue;
                }

                if (commandAttribute.GetType() == typeof(CommandNonGroupAttribute))
                {
                    continue;
                }

                ChildCommands.Add(new ChatCommand(commandAttribute, (HandleCommandDelegate)method.CreateDelegate(typeof(HandleCommandDelegate))));
            }

            foreach (var nestedType in type.GetNestedTypes(BindingFlags.NonPublic))
            {
                var groupAttribute = nestedType.GetCustomAttribute <CommandGroupAttribute>(true);
                if (groupAttribute == null)
                {
                    continue;
                }

                ChildCommands.Add(new ChatCommand(nestedType, groupAttribute));
            }

            ChildCommands = ChildCommands.OrderBy(p => string.IsNullOrEmpty(p.Name)).ThenBy(p => p.Name).ToList();
        }