3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
8 // QueryOperatorEnumerator.cs
10 // <OWNER>Microsoft</OWNER>
12 // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
14 using System.Collections;
15 using System.Collections.Generic;
16 using System.Diagnostics.Contracts;
18 using System.Core; // for System.Core.SR
21 namespace System.Linq.Parallel
24 /// A common enumerator type that unifies all query operator enumerators.
26 /// <typeparam name="TElement"></typeparam>
27 /// <typeparam name="TKey"></typeparam>
28 internal abstract class QueryOperatorEnumerator<TElement, TKey>
30 // Moves the position of the enumerator forward by one, and simultaneously returns
31 // the (new) current element and key. If empty, false is returned.
32 internal abstract bool MoveNext(ref TElement currentElement, ref TKey currentKey);
34 // Standard implementation of the disposable pattern.
40 protected virtual void Dispose(bool disposing)
42 // This is a no-op by default. Subclasses can override.
45 internal virtual void Reset()
47 // This is a no-op by default. Subclasses can override.
50 //-----------------------------------------------------------------------------------
51 // A simple way to turn a query operator enumerator into a "classic" one.
54 internal IEnumerator<TElement> AsClassicEnumerator()
56 return new QueryOperatorClassicEnumerator(this);
59 class QueryOperatorClassicEnumerator : IEnumerator<TElement>
61 private QueryOperatorEnumerator<TElement, TKey> m_operatorEnumerator;
62 private TElement m_current;
64 internal QueryOperatorClassicEnumerator(QueryOperatorEnumerator<TElement, TKey> operatorEnumerator)
66 Contract.Assert(operatorEnumerator != null);
67 m_operatorEnumerator = operatorEnumerator;
70 public bool MoveNext()
72 TKey keyUnused = default(TKey);
73 return m_operatorEnumerator.MoveNext(ref m_current, ref keyUnused);
76 public TElement Current
78 get { return m_current; }
81 object IEnumerator.Current
83 get { return m_current; }
88 m_operatorEnumerator.Dispose();
89 m_operatorEnumerator = null;
94 m_operatorEnumerator.Reset();