protected static object GetTarget(Delegate callback)
 {
     if (callback == null)
     {
         throw new ArgumentNullException("callback");
     }
     ContextItemManager.ICallbackProxy callbackProxy = callback.Target as ContextItemManager.ICallbackProxy;
     if (callbackProxy != null)
     {
         return(callbackProxy.OriginalTarget);
     }
     return(callback.Target);
 }
        protected static Delegate RemoveCallback(Delegate existing, Delegate toRemove)
        {
            if (existing == null)
            {
                return((Delegate)null);
            }
            if (toRemove == null)
            {
                return(existing);
            }
            ContextItemManager.ICallbackProxy callbackProxy1 = toRemove.Target as ContextItemManager.ICallbackProxy;
            if (callbackProxy1 == null)
            {
                return(Delegate.Remove(existing, toRemove));
            }
            toRemove = callbackProxy1.OriginalDelegate;
            Delegate[] invocationList = existing.GetInvocationList();
            bool       flag           = false;

            for (int index = 0; index < invocationList.Length; ++index)
            {
                Delegate @delegate = invocationList[index];
                ContextItemManager.ICallbackProxy callbackProxy2 = @delegate.Target as ContextItemManager.ICallbackProxy;
                if (callbackProxy2 != null)
                {
                    @delegate = callbackProxy2.OriginalDelegate;
                }
                if (@delegate.Equals((object)toRemove))
                {
                    invocationList[index] = (Delegate)null;
                    flag = true;
                }
            }
            if (flag)
            {
                existing = (Delegate)null;
                foreach (Delegate b in invocationList)
                {
                    if (b != null)
                    {
                        existing = existing != null?Delegate.Combine(existing, b) : b;
                    }
                }
            }
            return(existing);
        }