DisposableCollectionWrapper.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Common / Utils / DisposableCollectionWrapper.cs / 1305376 / 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()
        { 
            // Technically, calling GC.SuppressFinalize is not required because the class does not 
            // have a finalizer, but it does no harm, protects against the case where a finalizer is added
            // in the future, and prevents an FxCop warning. 
            GC.SuppressFinalize(this);
            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