public static ICancelValueContainer CreateCancelContainer <TCancel>(ref TCancel reason) { ICancelValueContainer cancelValue; if (typeof(TCancel).IsValueType) { cancelValue = CancelContainer <TCancel> .GetOrCreate(ref reason); } else { #if CSHARP_7_OR_LATER if (((object)reason) is ICancelationToContainer internalCancelation) #else ICancelationToContainer internalCancelation = reason as ICancelationToContainer; if (internalCancelation != null) #endif { // reason is an internal cancelation object, get its container instead of wrapping it. cancelValue = internalCancelation.ToContainer(); } else if (ReferenceEquals(reason, null) || reason is OperationCanceledException) { // Use void container instead of wrapping OperationCanceledException, or if reason is null. cancelValue = CancelContainerVoid.GetOrCreate(); } else { // Only need to create one object pool for reference types. object o = reason; cancelValue = CancelContainer <object> .GetOrCreate(ref o); } } return(cancelValue); }
public void SetCanceled() { ValueContainer = CancelContainerVoid.GetOrCreate(); InvokeCallbacks(); }
public ICancelValueContainer ToContainer() { return CancelContainerVoid.GetOrCreate(); }
public IValueContainer ToContainer(ITraceable traceable) { return(CancelContainerVoid.GetOrCreate()); }