コード例 #1
0
        /// <summary>
        /// Adds an MBCEventHandler delegate to the events to invoke.
        /// </summary>
        /// <param name="del"></param>
        protected virtual void AddEventHandler(MBCEventHandler del)
        {
            MethodInfo method = del.Method;

            object[] attributes = method.GetCustomAttributes(typeof(EventFilterAttribute), false);
            if (attributes.Length > 0)
            {
                foreach (object o in attributes)
                {
                    EventFilterAttribute attribute = (EventFilterAttribute)o;
                    if (attribute.Event == typeof(MatchAddPlayerEvent))
                    {
                        Console.WriteLine("Hello");
                    }
                    if (!filters.ContainsKey(attribute.Event))
                    {
                        filters.Add(attribute.Event, new List <MBCEventHandler>());
                    }
                    filters[attribute.Event].Add(del);
                }
            }
            else
            {
                noFilters.Add(del);
            }
        }
コード例 #2
0
        /// <summary>
        /// Removes an event handler from being invoked.
        /// </summary>
        /// <param name="del"></param>
        protected virtual void RemoveEventHandler(MBCEventHandler del)
        {
            MethodInfo method = del.Method;

            object[] attributes = method.GetCustomAttributes(typeof(EventFilterAttribute), false);
            if (attributes.Length == 0)
            {
                foreach (object o in attributes)
                {
                    EventFilterAttribute attribute = (EventFilterAttribute)o;
                    if (filters.ContainsKey(attribute.Event))
                    {
                        filters[attribute.Event].Remove(del);
                    }
                }
            }
            else
            {
                noFilters.Remove(del);
            }
        }