Exemple #1
0
        /// <summary>Add an event handler.</summary>
        /// <param name="handler">The event handler.</param>
        /// <param name="mod">The mod which added the event handler.</param>
        public void Add(EventHandler <TEventArgs> handler, IModMetadata mod)
        {
            lock (this.Handlers)
            {
                EventPriority priority       = handler.Method.GetCustomAttribute <EventPriorityAttribute>()?.Priority ?? EventPriority.Normal;
                var           managedHandler = new ManagedEventHandler <TEventArgs>(handler, this.RegistrationIndex++, priority, mod);

                this.Handlers.Add(managedHandler);
                this.CachedHandlers = null;
                this.HasNewHandlers = true;
            }
        }
Exemple #2
0
 /*********
 ** Private methods
 *********/
 /// <summary>Log an exception from an event handler.</summary>
 /// <param name="handler">The event handler instance.</param>
 /// <param name="ex">The exception that was raised.</param>
 protected void LogError(ManagedEventHandler <TEventArgs> handler, Exception ex)
 {
     handler.SourceMod.LogAsMod($"This mod failed in the {this.EventName} event. Technical details: \n{ex.GetLogSummary()}", LogLevel.Error);
 }