ParallelEnumerableWrapper.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 / ParallelEnumerableWrapper.cs / 1305376 / ParallelEnumerableWrapper.cs

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

using System.Collections; 
using System.Collections.Generic;
using System.Diagnostics.Contracts; 
 
namespace System.Linq.Parallel
{ 
    /// 
    /// A simple implementation of the ParallelQuery{object} interface which wraps an
    /// underlying IEnumerable, such that it can be used in parallel queries.
    ///  
    internal class ParallelEnumerableWrapper : ParallelQuery
    { 
 
        private readonly IEnumerable m_source; // The wrapped enumerable object.
 
        //------------------------------------------------------------------------------------
        // Instantiates a new wrapper object.
        //
 
        internal ParallelEnumerableWrapper(Collections.IEnumerable source)
            : base(QuerySettings.Empty) 
        { 
            Contract.Assert(source != null);
            m_source = source; 
        }

        internal override IEnumerator GetEnumeratorUntyped()
        { 
            return m_source.GetEnumerator();
        } 
 
        public override IEnumerator GetEnumerator()
        { 
            return new EnumerableWrapperWeakToStrong(m_source).GetEnumerator();
        }
    }
 
    /// 
    /// A simple implementation of the ParallelQuery{T} interface which wraps an 
    /// underlying IEnumerable{T}, such that it can be used in parallel queries. 
    /// 
    ///  
    internal class ParallelEnumerableWrapper : ParallelQuery
    {

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

        //----------------------------------------------------------------------------------- 
        // Instantiates a new wrapper object. 
        //
        // Arguments: 
        //     wrappedEnumerable   - the underlying enumerable object being wrapped
        //
        // Notes:
        //     The analysisOptions and degreeOfParallelism settings are optional.  Passing null 
        //     indicates that the system defaults should be used instead.
        // 
 
        internal ParallelEnumerableWrapper(IEnumerable wrappedEnumerable)
            : base(QuerySettings.Empty) 
        {
            Contract.Assert(wrappedEnumerable != null, "wrappedEnumerable must not be null.");

            m_wrappedEnumerable = wrappedEnumerable; 
        }
 
        //----------------------------------------------------------------------------------- 
        // Retrieves the wrapped enumerable object.
        // 

        internal IEnumerable WrappedEnumerable
        {
            get { return m_wrappedEnumerable; } 
        }
 
        //----------------------------------------------------------------------------------- 
        // Implementations of GetEnumerator that just delegate to the wrapped enumerable.
        // 

        public override IEnumerator GetEnumerator()
        {
            Contract.Assert(m_wrappedEnumerable != null); 
            return m_wrappedEnumerable.GetEnumerator();
        } 
    } 
}

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

using System.Collections; 
using System.Collections.Generic;
using System.Diagnostics.Contracts; 
 
namespace System.Linq.Parallel
{ 
    /// 
    /// A simple implementation of the ParallelQuery{object} interface which wraps an
    /// underlying IEnumerable, such that it can be used in parallel queries.
    ///  
    internal class ParallelEnumerableWrapper : ParallelQuery
    { 
 
        private readonly IEnumerable m_source; // The wrapped enumerable object.
 
        //------------------------------------------------------------------------------------
        // Instantiates a new wrapper object.
        //
 
        internal ParallelEnumerableWrapper(Collections.IEnumerable source)
            : base(QuerySettings.Empty) 
        { 
            Contract.Assert(source != null);
            m_source = source; 
        }

        internal override IEnumerator GetEnumeratorUntyped()
        { 
            return m_source.GetEnumerator();
        } 
 
        public override IEnumerator GetEnumerator()
        { 
            return new EnumerableWrapperWeakToStrong(m_source).GetEnumerator();
        }
    }
 
    /// 
    /// A simple implementation of the ParallelQuery{T} interface which wraps an 
    /// underlying IEnumerable{T}, such that it can be used in parallel queries. 
    /// 
    ///  
    internal class ParallelEnumerableWrapper : ParallelQuery
    {

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

        //----------------------------------------------------------------------------------- 
        // Instantiates a new wrapper object. 
        //
        // Arguments: 
        //     wrappedEnumerable   - the underlying enumerable object being wrapped
        //
        // Notes:
        //     The analysisOptions and degreeOfParallelism settings are optional.  Passing null 
        //     indicates that the system defaults should be used instead.
        // 
 
        internal ParallelEnumerableWrapper(IEnumerable wrappedEnumerable)
            : base(QuerySettings.Empty) 
        {
            Contract.Assert(wrappedEnumerable != null, "wrappedEnumerable must not be null.");

            m_wrappedEnumerable = wrappedEnumerable; 
        }
 
        //----------------------------------------------------------------------------------- 
        // Retrieves the wrapped enumerable object.
        // 

        internal IEnumerable WrappedEnumerable
        {
            get { return m_wrappedEnumerable; } 
        }
 
        //----------------------------------------------------------------------------------- 
        // Implementations of GetEnumerator that just delegate to the wrapped enumerable.
        // 

        public override IEnumerator GetEnumerator()
        {
            Contract.Assert(m_wrappedEnumerable != null); 
            return m_wrappedEnumerable.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