public Delegate GetInvocationList()
        {
            DelegateBreakout[] currentDelegates = delegates;
            Delegate           resultDelegate   = null;

            for (int delegateIndex = 0; delegateIndex < currentDelegates.Length; delegateIndex++)
            {
                DelegateBreakout breakout = currentDelegates[delegateIndex];
                Delegate         @delegate;
                if (breakout.TryGetDelegate(delegateType, out @delegate))
                {
                    resultDelegate = Delegate.Combine(resultDelegate, @delegate);
                }
            }
            return(resultDelegate);
        }
        public WeakDelegateSuragate Remove(WeakDelegateSuragate other)
        {
            DelegateBreakout[]      toRemove  = other.delegates;
            List <DelegateBreakout> breakouts = new List <DelegateBreakout>(delegates.Length);

            DelegateBreakout[] currentDelegates = delegates;
            for (int i = 0; i < currentDelegates.Length; i++)
            {
                DelegateBreakout breakout = currentDelegates[i];
                if (Array.IndexOf(toRemove, breakout) == -1 && breakout.Alive)
                {
                    breakouts.Add(breakout);
                }
            }
            WeakDelegateSuragate suragate = new WeakDelegateSuragate(delegateType, breakouts.Count);

            breakouts.CopyTo(suragate.delegates);
            return(suragate);
        }
 public WeakDelegateSuragate Remove(Delegate @delegate)
 {
     using (DelegateBreakout toRemove = new DelegateBreakout(@delegate, null))
     {
         List <DelegateBreakout> breakouts        = new List <DelegateBreakout>(delegates.Length);
         DelegateBreakout[]      currentDelegates = delegates;
         for (int i = 0; i < currentDelegates.Length; i++)
         {
             DelegateBreakout breakout = currentDelegates[i];
             if (breakout != toRemove && breakout.Alive)
             {
                 breakouts.Add(breakout);
             }
         }
         WeakDelegateSuragate suragate = new WeakDelegateSuragate(delegateType, breakouts.Count);
         breakouts.CopyTo(suragate.delegates);
         return(suragate);
     }
 }
 private void Clean()
 {
     lock (this)
     {
         DelegateBreakout[]      currentDelegates = delegates;
         List <DelegateBreakout> stillAlive       = new List <DelegateBreakout>(currentDelegates.Length);
         for (int delegateIndex = 0; delegateIndex < currentDelegates.Length; delegateIndex++)
         {
             DelegateBreakout breakout = currentDelegates[delegateIndex];
             if (breakout.Alive)
             {
                 stillAlive.Add(breakout);
             }
             else
             {
                 breakout.Dispose();
             }
         }
         if (stillAlive.Count != currentDelegates.Length)
         {
             Interlocked.Exchange(ref delegates, stillAlive.ToArray());
         }
     }
 }