Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 public void SetCanceled()
 {
     ValueContainer = CancelContainerVoid.GetOrCreate();
     InvokeCallbacks();
 }
Exemplo n.º 3
0
 public ICancelValueContainer ToContainer()
 {
     return CancelContainerVoid.GetOrCreate();
 }
Exemplo n.º 4
0
 public IValueContainer ToContainer(ITraceable traceable)
 {
     return(CancelContainerVoid.GetOrCreate());
 }