Ejemplo n.º 1
0
        public static DisposeGuard Guard(this IDisposable disposable)
        {
            if (disposable == null)
            {
                throw new ArgumentNullException("disposable");
            }
            DisposeGuard result = default(DisposeGuard);

            result.Add <IDisposable>(disposable);
            return(result);
        }
Ejemplo n.º 2
0
        private IDisposable SwapSlot(int index, IDisposable newValue)
        {
            switch (index)
            {
            case 0:
                return(DisposeGuard.Swap(ref this.fixedSlot0, newValue));

            case 1:
                return(DisposeGuard.Swap(ref this.fixedSlot1, newValue));

            case 2:
                return(DisposeGuard.Swap(ref this.fixedSlot2, newValue));

            case 3:
                return(DisposeGuard.Swap(ref this.fixedSlot3, newValue));

            default:
                return(DisposeGuard.Swap(ref this.overflowSlots[index - 4], newValue));
            }
        }
Ejemplo n.º 3
0
        public T Add <T>(T disposable) where T : class, IDisposable
        {
            this.CheckDisposed();
            if (disposable == null)
            {
                return(disposable);
            }
            bool flag = false;

            try
            {
                this.AddGuardedObject(disposable);
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    DisposeGuard.DisposeIfPresent(disposable);
                }
            }
            return(disposable);
        }
Ejemplo n.º 4
0
 private void RemoveLastGuardedObject()
 {
     DisposeGuard.DisposeIfPresent(this.SwapSlot((int)(this.SlotCount - 1), null));
     this.SlotCount -= 1;
 }