protected static object GetTarget(Delegate callback) { if (callback == null) { throw new ArgumentNullException("callback"); } ServiceManager.ICallbackProxy callbackProxy = callback.Target as ServiceManager.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); } ServiceManager.ICallbackProxy callbackProxy1 = toRemove.Target as ServiceManager.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]; ServiceManager.ICallbackProxy callbackProxy2 = @delegate.Target as ServiceManager.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); }