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

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

using System.Collections; 
using System.Collections.Generic;
 
namespace System.Linq.Parallel 
{
    ///  
    /// We occ----ionally need a no-op enumerator to stand-in when we don't have data left
    /// within a partition's data stream. These are simple enumerable and enumerator
    /// implementations that always and consistently yield no elements.
    ///  
    /// 
    internal class EmptyEnumerable : ParallelQuery 
    { 
        private EmptyEnumerable()
            : base(QuerySettings.Empty) 
        {
        }

        // A singleton cached and shared among callers. 
        private static EmptyEnumerable s_instance;
        private static EmptyEnumerator s_enumeratorInstance; 
 
        internal static EmptyEnumerable Instance
        { 
            get
            {
                if (s_instance == null)
                { 
                    // There is no need for thread safety here.
                    s_instance = new EmptyEnumerable(); 
                } 

                return s_instance; 
            }
        }

        public override IEnumerator GetEnumerator() 
        {
            if (s_enumeratorInstance == null) 
            { 
                // There is no need for thread safety here.
                s_enumeratorInstance = new EmptyEnumerator(); 
            }

            return s_enumeratorInstance;
        } 
    }
 
    internal class EmptyEnumerator : QueryOperatorEnumerator, IEnumerator 
    {
        internal override bool MoveNext(ref T currentElement, ref int currentKey) 
        {
            return false;
        }
 
        // IEnumerator methods.
        public T Current { get { return default(T); } } 
        object IEnumerator.Current { get { return null; } } 
        public bool MoveNext() { return false; }
        void Collections.IEnumerator.Reset() { } 
    }
}

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

using System.Collections; 
using System.Collections.Generic;
 
namespace System.Linq.Parallel 
{
    ///  
    /// We occ----ionally need a no-op enumerator to stand-in when we don't have data left
    /// within a partition's data stream. These are simple enumerable and enumerator
    /// implementations that always and consistently yield no elements.
    ///  
    /// 
    internal class EmptyEnumerable : ParallelQuery 
    { 
        private EmptyEnumerable()
            : base(QuerySettings.Empty) 
        {
        }

        // A singleton cached and shared among callers. 
        private static EmptyEnumerable s_instance;
        private static EmptyEnumerator s_enumeratorInstance; 
 
        internal static EmptyEnumerable Instance
        { 
            get
            {
                if (s_instance == null)
                { 
                    // There is no need for thread safety here.
                    s_instance = new EmptyEnumerable(); 
                } 

                return s_instance; 
            }
        }

        public override IEnumerator GetEnumerator() 
        {
            if (s_enumeratorInstance == null) 
            { 
                // There is no need for thread safety here.
                s_enumeratorInstance = new EmptyEnumerator(); 
            }

            return s_enumeratorInstance;
        } 
    }
 
    internal class EmptyEnumerator : QueryOperatorEnumerator, IEnumerator 
    {
        internal override bool MoveNext(ref T currentElement, ref int currentKey) 
        {
            return false;
        }
 
        // IEnumerator methods.
        public T Current { get { return default(T); } } 
        object IEnumerator.Current { get { return null; } } 
        public bool MoveNext() { return false; }
        void Collections.IEnumerator.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