Пример #1
0
 public ModuleInfo(string Name, List <CommandInfo> Commands, List <Attribute> Attributes, CommandModuleBase Instance)
 {
     this.Name       = Name;
     this.Commands   = Commands;
     this.Attributes = Attributes;
     this.Instance   = Instance;
 }
Пример #2
0
        /// <summary>
        /// Converts class to Valour.Net module
        /// </summary>
        /// <param name="module">Class type to convert</param>
        public void BuildModule(Type module)
        {
            ConstructorInfo   constructor    = module.GetConstructor(Type.EmptyTypes);
            CommandModuleBase moduleInstance = (CommandModuleBase)constructor.Invoke(Array.Empty <object>());

            Module.Instance = moduleInstance;
            Module.Name     = module.Name;

            foreach (MethodInfo method in module.GetMethods().Where(m => m.GetCustomAttributes(typeof(CommandAttribute), false).Length > 0))
            {
                CommandBuilder builder = new();
                builder.BuildCommand(method, Module);
            }

            foreach (MethodInfo method in module.GetMethods().Where(m => m.GetCustomAttributes(typeof(EventAttribute), false).Length > 0))
            {
                InfoModels.EventInfo eventInfo = new();
                EventAttribute       EventAttr = (EventAttribute)method.GetCustomAttribute(typeof(EventAttribute));
                eventInfo.EventName  = EventAttr.Name;
                eventInfo.Method     = method;
                eventInfo.moduleInfo = Module;
                EventService._Events.Add(eventInfo);
            }
        }