Ejemplo n.º 1
0
        public void RemoveProcessor(IEventReceiverable requester)
        {
            var interfaces = requester.GetType().GetInterfaces();

            int length = interfaces.Length;

            for (int i = 0; i < length; i++)
            {
                var temp = interfaces[i];
                if (temp.IsGenericType && temp.GetGenericTypeDefinition() == typeof(IEventReceiverable <>))
                {
                    int type = temp.GetGenericArguments()[0].GetHashCode();
                    List <WeakWrapper <IEventReceiverable> > outProc = null;

                    if (processors.TryGetValue(type, out outProc))
                    {
                        int index = processors[type].FindIndex(weak => weak.Value == requester);

                        if (index != -1)
                        {
                            processors[type].RemoveAt(index);
                            return;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void AddProcessor(IEventReceiverable requester)
        {
            var interfaces = requester.GetType().GetInterfaces();

            int length = interfaces.Length;

            for (int i = 0; i < length; i++)
            {
                var temp = interfaces[i];
                if (temp.IsGenericType && temp.GetGenericTypeDefinition() == typeof(IEventReceiverable <>))
                {
                    int type = temp.GetGenericArguments()[0].GetHashCode();
                    List <WeakWrapper <IEventReceiverable> > outProc = null;

                    if (processors.TryGetValue(type, out outProc))
                    {
                        WeakWrapper <IEventReceiverable> wrap = new WeakWrapper <IEventReceiverable>(requester);
                        processors[type].Add(wrap);
                        return;
                    }

                    processors.Add(type, new List <WeakWrapper <IEventReceiverable> >()
                    {
                        new WeakWrapper <IEventReceiverable>(requester)
                    });
                }
            }
        }