EnumerableWrapperWeakToStrong.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / System / Linq / Parallel / Enumerables / EnumerableWrapperWeakToStrong.cs / 1305376 / EnumerableWrapperWeakToStrong.cs

                            // ==++== 
//
//   Copyright (c) Microsoft Corporation.  All rights reserved.
//
// ==--== 
// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
// 
// EnumerableWrapperWeakToStrong.cs 
//
// [....] 
//
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

using System.Collections; 
using System.Collections.Generic;
using System.Diagnostics.Contracts; 
 
namespace System.Linq.Parallel
{ 
    /// 
    /// A simple implementation of the IEnumerable{object} interface which wraps
    /// a weakly typed IEnumerable object, allowing it to be accessed as a strongly typed
    /// IEnumerable{object}. 
    /// 
    internal class EnumerableWrapperWeakToStrong : IEnumerable 
    { 

        private readonly IEnumerable m_wrappedEnumerable; // The wrapped enumerable object. 

        //------------------------------------------------------------------------------------
        // Instantiates a new wrapper object.
        // 

        internal EnumerableWrapperWeakToStrong(IEnumerable wrappedEnumerable) 
        { 
            Contract.Assert(wrappedEnumerable != null);
            m_wrappedEnumerable = wrappedEnumerable; 
        }

        IEnumerator IEnumerable.GetEnumerator()
        { 
            return ((IEnumerable)this).GetEnumerator();
        } 
 
        public IEnumerator GetEnumerator()
        { 
            return new WrapperEnumeratorWeakToStrong(m_wrappedEnumerable.GetEnumerator());
        }

        //----------------------------------------------------------------------------------- 
        // A wrapper over IEnumerator that provides IEnumerator interface
        // 
 
        class WrapperEnumeratorWeakToStrong : IEnumerator
        { 

            private IEnumerator m_wrappedEnumerator; // The weakly typed enumerator we've wrapped.

            //----------------------------------------------------------------------------------- 
            // Wrap the specified enumerator in a new weak-to-strong converter.
            // 
 
            internal WrapperEnumeratorWeakToStrong(IEnumerator wrappedEnumerator)
            { 
                Contract.Assert(wrappedEnumerator != null);
                m_wrappedEnumerator = wrappedEnumerator;
            }
 
            //-----------------------------------------------------------------------------------
            // These are all really simple IEnumerator implementations that simply 
            // forward to the corresponding weakly typed IEnumerator methods. 
            //
 
            object IEnumerator.Current
            {
                get { return m_wrappedEnumerator.Current; }
            } 

            object IEnumerator.Current 
            { 
                get { return m_wrappedEnumerator.Current; }
            } 

            void IDisposable.Dispose()
            {
                IDisposable disposable = m_wrappedEnumerator as IDisposable; 
                if (disposable != null)
                { 
                    disposable.Dispose(); 
                }
            } 

            bool IEnumerator.MoveNext()
            {
                return m_wrappedEnumerator.MoveNext(); 
            }
 
            void IEnumerator.Reset() 
            {
                m_wrappedEnumerator.Reset(); 
            }

        }
 
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// ==++== 
//
//   Copyright (c) Microsoft Corporation.  All rights reserved.
//
// ==--== 
// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
// 
// EnumerableWrapperWeakToStrong.cs 
//
// [....] 
//
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

using System.Collections; 
using System.Collections.Generic;
using System.Diagnostics.Contracts; 
 
namespace System.Linq.Parallel
{ 
    /// 
    /// A simple implementation of the IEnumerable{object} interface which wraps
    /// a weakly typed IEnumerable object, allowing it to be accessed as a strongly typed
    /// IEnumerable{object}. 
    /// 
    internal class EnumerableWrapperWeakToStrong : IEnumerable 
    { 

        private readonly IEnumerable m_wrappedEnumerable; // The wrapped enumerable object. 

        //------------------------------------------------------------------------------------
        // Instantiates a new wrapper object.
        // 

        internal EnumerableWrapperWeakToStrong(IEnumerable wrappedEnumerable) 
        { 
            Contract.Assert(wrappedEnumerable != null);
            m_wrappedEnumerable = wrappedEnumerable; 
        }

        IEnumerator IEnumerable.GetEnumerator()
        { 
            return ((IEnumerable)this).GetEnumerator();
        } 
 
        public IEnumerator GetEnumerator()
        { 
            return new WrapperEnumeratorWeakToStrong(m_wrappedEnumerable.GetEnumerator());
        }

        //----------------------------------------------------------------------------------- 
        // A wrapper over IEnumerator that provides IEnumerator interface
        // 
 
        class WrapperEnumeratorWeakToStrong : IEnumerator
        { 

            private IEnumerator m_wrappedEnumerator; // The weakly typed enumerator we've wrapped.

            //----------------------------------------------------------------------------------- 
            // Wrap the specified enumerator in a new weak-to-strong converter.
            // 
 
            internal WrapperEnumeratorWeakToStrong(IEnumerator wrappedEnumerator)
            { 
                Contract.Assert(wrappedEnumerator != null);
                m_wrappedEnumerator = wrappedEnumerator;
            }
 
            //-----------------------------------------------------------------------------------
            // These are all really simple IEnumerator implementations that simply 
            // forward to the corresponding weakly typed IEnumerator methods. 
            //
 
            object IEnumerator.Current
            {
                get { return m_wrappedEnumerator.Current; }
            } 

            object IEnumerator.Current 
            { 
                get { return m_wrappedEnumerator.Current; }
            } 

            void IDisposable.Dispose()
            {
                IDisposable disposable = m_wrappedEnumerator as IDisposable; 
                if (disposable != null)
                { 
                    disposable.Dispose(); 
                }
            } 

            bool IEnumerator.MoveNext()
            {
                return m_wrappedEnumerator.MoveNext(); 
            }
 
            void IEnumerator.Reset() 
            {
                m_wrappedEnumerator.Reset(); 
            }

        }
 
    }
} 

// 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