// TODO: No error checking at the moment, needs work to stop people doing silly things. private void ExecuteHandlerMethod(IrcMessageData data, ModuleMessageHandler handler, Match match) { var method = GetType().GetMethod(handler.Method, BindingFlags.NonPublic | BindingFlags.Instance); if(method == null) return; var arguments = method.GetParameters() .Select(parameter => { if (parameter.Position == 0) return data; if (match.Groups[parameter.Name] == null) return Activator.CreateInstance(parameter.ParameterType); return TypeDescriptor.GetConverter(parameter.ParameterType) .ConvertFromString(match.Groups[parameter.Name].Value); }) .ToArray(); method.Invoke(this, arguments); }
public void AddHandler(ModuleMessageHandler handler) { _handlers.Add(handler); }