3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
10 // <OWNER>Microsoft</OWNER>
12 // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
14 using System.Collections;
15 using System.Collections.Generic;
16 using System.Diagnostics.Contracts;
18 namespace System.Linq.Parallel
21 /// The QueryResults{T} is a class representing the results of the query. There may
22 /// be different ways the query results can be manipulated. Currently, two ways are
25 /// 1. Open the query results as a partitioned stream by calling GivePartitionedStream
26 /// and pass a generic action as an argument.
28 /// 2. Access individual elements of the results list by calling GetElement(index) and
29 /// ElementsCount. This method of accessing the query results is available only if
30 /// IsIndexible return true.
32 /// <typeparam name="T"></typeparam>
33 internal abstract class QueryResults<T> : IList<T>
35 //-----------------------------------------------------------------------------------
36 // Gets the query results represented as a partitioned stream. Instead of returning
37 // the PartitionedStream, we instead call recipient.Receive<TKey>(...). That way,
38 // the code that receives the partitioned stream has access to the TKey type.
41 // recipient - the object that the partitioned stream will be passed to
44 internal abstract void GivePartitionedStream(IPartitionedStreamRecipient<T> recipient);
46 //-----------------------------------------------------------------------------------
47 // Returns whether the query results are indexible. If this property is true, the
48 // user can call GetElement(index) and ElementsCount. If it is false, both
49 // GetElement(index) and ElementsCount should throw InvalidOperationException.
52 internal virtual bool IsIndexible
57 //-----------------------------------------------------------------------------------
58 // Returns index-th element in the query results
61 // IsIndexible returns true
62 // 0 <= index < ElementsCount
65 internal virtual T GetElement(int index)
67 Contract.Assert(false, "GetElement property is not supported by non-indexible query results");
68 throw new NotSupportedException();
71 //-----------------------------------------------------------------------------------
72 // Returns the number of elements in the query results
75 // IsIndexible returns true
78 internal virtual int ElementsCount
82 Contract.Assert(false, "ElementsCount property is not supported by non-indexible query results");
83 throw new NotSupportedException();
88 // An assortment of methods we need to support in order to implement the IList interface
91 int IList<T>.IndexOf(T item)
93 throw new NotSupportedException();
96 void IList<T>.Insert(int index, T item)
98 throw new NotSupportedException();
101 void IList<T>.RemoveAt(int index)
103 throw new NotSupportedException();
106 public T this[int index]
108 get { return GetElement(index); }
111 throw new NotSupportedException();
115 void ICollection<T>.Add(T item)
117 throw new NotSupportedException();
120 void ICollection<T>.Clear()
122 throw new NotSupportedException();
125 bool ICollection<T>.Contains(T item)
127 throw new NotSupportedException();
130 void ICollection<T>.CopyTo(T[] array, int arrayIndex)
132 throw new NotSupportedException();
137 get { return ElementsCount; }
140 bool ICollection<T>.IsReadOnly
145 bool ICollection<T>.Remove(T item)
147 throw new NotSupportedException();
150 IEnumerator<T> IEnumerable<T>.GetEnumerator()
152 for (int index = 0; index < Count; index++)
154 yield return this[index];
158 IEnumerator IEnumerable.GetEnumerator()
160 return ((IEnumerable<T>)this).GetEnumerator();