Ejemplo n.º 1
0
        /// <summary>
        /// Removes a <see cref="Delegate"/> from the <see cref="WeakMulticastDelegate"/>.
        /// </summary>
        /// <param name="delegate">The <see cref="Delegate"/> to remove.</param>
        public void Remove(Delegate @delegate)
        {
            if (@delegate == null)
            {
                return;
            }

            for (int i = _delegates.Count - 1; i >= 0; i--)
            {
                InternalWeakDelegate weakDelegate = _delegates[i];
                if (weakDelegate.TargetReference != null)
                {
                    // The delegate method is an object method.
                    object target = weakDelegate.TargetReference.Target;
                    if (target == null)
                    {
                        // Remove garbage collected entry.
                        _delegates.RemoveAt(i);
                    }
                    else if (target == @delegate.Target
#if !NETFX_CORE && !NET45
                             && weakDelegate.MethodInfo.Equals(@delegate.Method))
#else
                             && weakDelegate.MethodInfo.Equals(@delegate.GetMethodInfo()))
#endif

                    {
                        // Remove matching entry.
                        _delegates.RemoveAt(i);
                        break;
                    }
                }
                else
                {
                    // The delegate method is a class method.
                    if (@delegate.Target == null
#if !NETFX_CORE && !NET45
                        && weakDelegate.MethodInfo.Equals(@delegate.Method))
#else
                        && weakDelegate.MethodInfo.Equals(@delegate.GetMethodInfo()))
#endif
                    {
                        // Remove matching entry.
                        _delegates.RemoveAt(i);
                        break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        //--------------------------------------------------------------
        #region Creation & Cleanup
        //--------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance of the <see cref="WeakDelegate"/> class.
        /// </summary>
        /// <param name="delegate">
        /// The original <see cref="System.Delegate"/> to create a weak reference for.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="delegate"/> is <see langword="null"/>.
        /// </exception>
        public WeakDelegate(Delegate @delegate)
        {
            _internalWeakDelegate = new InternalWeakDelegate(@delegate);
        }
Ejemplo n.º 3
0
 //--------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance of the <see cref="WeakDelegate"/> class.
 /// </summary>
 /// <param name="delegate">
 /// The original <see cref="System.Delegate"/> to create a weak reference for.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="delegate"/> is <see langword="null"/>.
 /// </exception>
 public WeakDelegate(Delegate @delegate)
 {
     _internalWeakDelegate = new InternalWeakDelegate(@delegate);
 }