DisposableCollectionWrapper.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataEntity / System / Data / Common / Utils / DisposableCollectionWrapper.cs / 1 / DisposableCollectionWrapper.cs

                            //------------------------------------------------------------------------------ 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// [....] 
// [....]
//----------------------------------------------------------------------------- 
using System.Collections.Generic; 
using System.Linq;
using System.Text; 
using System.Diagnostics;

namespace System.Data.Common.Utils
{ 
    internal class DisposableCollectionWrapper : IDisposable, IEnumerable where T : IDisposable
    { 
        IEnumerable _enumerable; 
        internal DisposableCollectionWrapper(IEnumerable enumerable)
        { 
            Debug.Assert(enumerable != null, "don't pass in a null enumerable");
            _enumerable = enumerable;
        }
 
        public void  Dispose()
        { 
            if(_enumerable != null) 
            {
                foreach(T item in _enumerable) 
                {
                    if(item != null)
                    {
                        item.Dispose(); 
                    }
                } 
            } 
        }
 
        public IEnumerator GetEnumerator()
        {
            return _enumerable.GetEnumerator();
        } 

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() 
        { 
            return ((System.Collections.IEnumerable)_enumerable).GetEnumerator();
        } 
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------ 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// [....] 
// [....]
//----------------------------------------------------------------------------- 
using System.Collections.Generic; 
using System.Linq;
using System.Text; 
using System.Diagnostics;

namespace System.Data.Common.Utils
{ 
    internal class DisposableCollectionWrapper : IDisposable, IEnumerable where T : IDisposable
    { 
        IEnumerable _enumerable; 
        internal DisposableCollectionWrapper(IEnumerable enumerable)
        { 
            Debug.Assert(enumerable != null, "don't pass in a null enumerable");
            _enumerable = enumerable;
        }
 
        public void  Dispose()
        { 
            if(_enumerable != null) 
            {
                foreach(T item in _enumerable) 
                {
                    if(item != null)
                    {
                        item.Dispose(); 
                    }
                } 
            } 
        }
 
        public IEnumerator GetEnumerator()
        {
            return _enumerable.GetEnumerator();
        } 

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() 
        { 
            return ((System.Collections.IEnumerable)_enumerable).GetEnumerator();
        } 
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.

                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK