internal EventHandler(Action <T> handlerAction, EventHandlerOptions options)
        {
            HandlerAction = handlerAction;
            Options       = options;

            HandlerInfo = handlerAction.Method;
        }
Beispiel #2
0
        public static void AddHandler(Type pathfinderEvent, MethodInfo handler, EventHandlerOptions options = default)
        {
            pathfinderEvent.ThrowNotInherit <PathfinderEvent>(nameof(pathfinderEvent));
            var parameters = handler.GetParameters();

            if (parameters.Length != 1 || parameters[0].ParameterType != pathfinderEvent)
            {
                throw new ArgumentException("Handler method must have one parameter of the same type of event you're subscribing to!", nameof(handler));
            }

            object handlerDelegate = typeof(AccessTools)
                                     .GetMethod("MethodDelegate")
                                     .MakeGenericMethod(typeof(Action <>).MakeGenericType(pathfinderEvent))
                                     .Invoke(null, new object[] { handler, null, true });

            object eventHandler = Activator.CreateInstance(
                typeof(EventHandler <>).MakeGenericType(pathfinderEvent),
                AccessTools.all,