From ac5c8e9fa0206934907299411e3131078840b318 Mon Sep 17 00:00:00 2001 From: Zontreck Date: Fri, 10 Apr 2020 16:53:17 -0700 Subject: [PATCH] adjust not-command to use methods instead. --- NonCommands/NotCommand.cs | 2 +- NonCommands/nRegistry.cs | 19 +++++++------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/NonCommands/NotCommand.cs b/NonCommands/NotCommand.cs index 52ab15f..1ab508e 100644 --- a/NonCommands/NotCommand.cs +++ b/NonCommands/NotCommand.cs @@ -4,7 +4,7 @@ using System.Text; namespace Bot.NonCommands { - [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] public class NotCommand : Attribute { public NotCommand() diff --git a/NonCommands/nRegistry.cs b/NonCommands/nRegistry.cs index 4519bca..afdd8b9 100644 --- a/NonCommands/nRegistry.cs +++ b/NonCommands/nRegistry.cs @@ -17,28 +17,23 @@ namespace Bot.NonCommands { foreach(Type t in a.GetTypes()) { - if (t.IsClass) + if (t.IsClass && t!=null) { - try + foreach (MethodInfo mi in t.GetMethods()) { - - foreach (NotCommand NC in (NotCommand[])t.GetCustomAttributes(false)) + NotCommand[] nc = (NotCommand[])mi.GetCustomAttributes(typeof(NotCommand), false); + if (nc.Length>0) { - MethodInfo mi = t.GetMethod("handle"); - ThreadStart work = delegate { + + mi.Invoke(Activator.CreateInstance(mi.DeclaringType), new object[] { request, agentKey, agentName, sourceLoc, originator }); }; Thread T = new Thread(work); - - - // _mi.Invoke(Activator.CreateInstance(_mi.DeclaringType), new object[] { }); T.Start(); - } - }catch(Exception e) - { + } } } }