Esempio n. 1
0
 public PrioritizedEventHandler(EventHandler <TArgsType> handler, EventPriority priority, bool ignoreCancel = false, string callerTypeName = "")
 {
     Event          = handler;
     Priority       = priority;
     IgnoreCancel   = ignoreCancel;
     CallerTypeName = callerTypeName;
 }
Esempio n. 2
0
        private void addHandler(Assembly asm, EventHandler <TArgs> handler, EventPriority priority, bool ignoreCancel)
        {
            // Attempt to find the calling plugin.
            // The assembly type will be used so events can automatically be destroyed when the mod is disabled or reloaded.
            // I (Cyral) have tried reflection and a bunch of ideas, but decided that it is best to try
            // and remove the events we can. In certain cases the author will manually have to remove events however.
            var callerTypeName = string.Empty;

            if (!asm.FullName.StartsWith("Alloy.API") && !asm.FullName.StartsWith("Alloy.Loader"))
            {
                // If found, find the main type name that inherits from the plugin class.
                var types      = asm.GetTypes();
                var pluginType = typeof(Mod);
                var mainType   = types.FirstOrDefault(type => pluginType.IsAssignableFrom(type));
                if (mainType != null)
                {
                    callerTypeName = mainType.FullName;
                }
            }
            handlers.Add(new PrioritizedEventHandler <TArgs>(handler, priority, ignoreCancel, callerTypeName));
            handlers.Sort((a, b) => ((int)a.Priority).CompareTo(b.Priority)); // Sort by priority
        }
Esempio n. 3
0
        /// <summary>
        /// Adds a handler to this event.
        /// </summary>
        /// <param name="handler">Delegate to be invoked when event is ran.</param>
        /// <param name="priority">
        /// The priority order of this handler. LOWER priorities are called FIRST, and higher priorities are
        /// called last. The default priority is 'Normal'.
        /// </param>
        /// <param name="ignoreCancel">If true, the handler will be executed even if a previous handler cancelled the event.</param>
        /// <remarks>
        /// For information on the priority ordering system, see <c>Priority</c>.
        /// </remarks>
        public void AddHandler(EventHandler <TArgs> handler, EventPriority priority, bool ignoreCancel = false)
        {
            var asm = Assembly.GetCallingAssembly();

            addHandler(asm, handler, priority, ignoreCancel);
        }