Exemplo n.º 1
0
        //---------------------------------------------------------------------------------------
        // Returns a QueryOperator<T> for any IEnumerable<T> data source. This will just do a
        // cast and return a reference to the same data source if the source is another query
        // operator, but will lazily allocate a scan operation and return that otherwise.
        //
        // Arguments:
        //    source  - any enumerable data source to be wrapped
        //
        // Return Value:
        //    A query operator.
        //

        internal static QueryOperator <TOutput> AsQueryOperator(IEnumerable <TOutput> source)
        {
            Contract.Assert(source != null);

            // Just try casting the data source to a query operator, in the case that
            // our child is just another query operator.
            QueryOperator <TOutput> sourceAsOperator = source as QueryOperator <TOutput>;

            if (sourceAsOperator == null)
            {
                OrderedParallelQuery <TOutput> orderedQuery = source as OrderedParallelQuery <TOutput>;
                if (orderedQuery != null)
                {
                    // We have to handle OrderedParallelQuery<T> specially. In all other cases,
                    // ParallelQuery *is* the QueryOperator<T>. But, OrderedParallelQuery<T>
                    // is not QueryOperator<T>, it only has a reference to one. Ideally, we
                    // would want SortQueryOperator<T> to inherit from OrderedParallelQuery<T>,
                    // but that conflicts with other constraints on our class hierarchy.
                    sourceAsOperator = (QueryOperator <TOutput>)orderedQuery.SortOperator;
                }
                else
                {
                    // If the cast failed, then the data source is a real piece of data. We
                    // just construct a new scan operator on top of it.
                    sourceAsOperator = new ScanQueryOperator <TOutput>(source);
                }
            }

            Contract.Assert(sourceAsOperator != null);

            return(sourceAsOperator);
        }
        internal override IEnumerator <TSource> GetEnumerator(ParallelMergeOptions?mergeOptions, bool suppressOrderPreservation)
        {
            ScanQueryOperator <TSource> childAsScan = m_child as ScanQueryOperator <TSource>;

            if (childAsScan != null)
            {
                return(childAsScan.Data.GetEnumerator());
            }
            return(base.GetEnumerator(mergeOptions, suppressOrderPreservation));
        }