/// <summary> /// Verifies that the target field is null and sets it to the non-null ISubscription provided /// or signal an InvalidOperationException if the target field is not null and not the Cancelled /// instance. In these cases, the new ISubscription is cancelled. /// </summary> /// <param name="current">The target field</param> /// <param name="s">The new ISubscription instance to set</param> /// <returns>True if successful, false if the target field is not empty</returns> public static bool Validate <T>(ref IQueueSubscription <T> current, IQueueSubscription <T> s) { if (s == null) { ReportSubscriptionNull(); return(false); } if (current != null) { s.Cancel(); if (current != CancelledQueueSubscription <T> .Instance) { ReportSubscriptionSet(); } return(false); } current = s; return(true); }