コード例 #1
0
 public override FdbAsyncIterator <TSource> Where(Func <TSource, bool> predicate)
 {
     return(FdbAsyncEnumerable.Filter <TSource>(
                m_source,
                m_filter.AndAlso(new AsyncFilterExpression <TSource>(predicate))
                ));
 }
        public override FdbAsyncIterator <TResult> Where(Func <TResult, bool> predicate)
        {
            if (predicate == null)
            {
                throw new ArgumentNullException("predicate");
            }

            // note: the only possible optimization here is if TSource == TResult, then we can combine both predicates
            // remember: limit/offset are applied AFTER the filtering, so can only combine if they are null
            // also, since transform is done after filtering, we can only optimize if transform is null (not allowed!) or the identity function
            if (m_limit == null &&
                (m_offset == null || m_offset.Value == 0) &&
                typeof(TSource) == typeof(TResult) &&                 //BUGBUG: type comparison maybe should check derived classes also ?
                m_transform.IsIdentity())
            {
                var filter = new AsyncFilterExpression <TSource>((Func <TSource, bool>)(Delegate) predicate);
                if (m_filter != null)
                {
                    filter = m_filter.AndAlso(filter);
                }

                //BUGBUG: if the query already has a select, it should be evaluated BEFORE the new filter,
                // but currently FdbWhereSelectAsyncIterator<> filters before transformations !

                return(new FdbWhereSelectAsyncIterator <TSource, TResult>(
                           m_source,
                           filter,
                           m_transform,
                           m_limit,
                           m_offset
                           ));
            }

            // no easy optimization...
            return(base.Where(predicate));
        }