示例#1
0
        public void Build()
        {
            Type type = GetType();

            foreach (MethodInfo info in type.GetMethods())
            {
                CommandAttribute attribute = info.GetCustomAttribute <CommandAttribute>();
                if (attribute == null)
                {
                    continue;
                }

                var handler = new CommandHandler(type, info);
                handlers.Add(attribute.Name, handler);
            }

            foreach (Type info in type.GetNestedTypes())
            {
                CommandAttribute attribute = info.GetCustomAttribute <CommandAttribute>();
                if (attribute == null)
                {
                    continue;
                }

                CommandCategory category = (CommandCategory)Activator.CreateInstance(info);
                category.Build();
                categories.Add(attribute.Name, category);
            }
        }
示例#2
0
        private void InitialiseCategories()
        {
            foreach (Type type in Assembly.GetExecutingAssembly().GetTypes()
                     .Where(t => typeof(CommandCategory).IsAssignableFrom(t) && !t.IsNested))
            {
                CommandAttribute attribute = type.GetCustomAttribute <CommandAttribute>();
                if (attribute == null)
                {
                    continue;
                }

                CommandCategory category = (CommandCategory)Activator.CreateInstance(type);
                category.Build();

                categories.Add(attribute.Name, category);
            }
        }