// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. #pragma warning disable 1591 using System.Collections.Generic; using System.Reactive.Joins; using System.Linq.Expressions; using System.Reflection; using System.Linq; namespace System.Reactive.Linq { public static partial class Qbservable { /* NOTE: Keep XML docs consistent with the corresponding Observable methods (modulo the IQbservableProvider parameters of course). */ /// /// Creates a pattern that matches when both observable sequences have an available element. /// /// The type of the elements in the left sequence. /// The type of the elements in the right sequence. /// Observable sequence to match with the right sequence. /// Observable sequence to match with the left sequence. /// Pattern object that matches when both observable sequences have an available element. /// or is null. public static QueryablePattern And(this IQbservable left, IObservable right) { if (left == null) throw new ArgumentNullException("left"); if (right == null) throw new ArgumentNullException("right"); return new QueryablePattern( Expression.Call( null, #if CRIPPLED_REFLECTION InfoOf(() => Qbservable.And(default(IQbservable), default(IObservable))), #else ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TLeft), typeof(TRight)), #endif left.Expression, GetSourceExpression(right) ) ); } /// /// Matches when the observable sequence has an available element and projects the element by invoking the selector function. /// /// The type of the elements in the source sequence. /// The type of the elements in the result sequence, returned by the selector function. /// Observable sequence to apply the selector on. /// Selector that will be invoked for elements in the source sequence. /// Plan that produces the projected results, to be fed (with other plans) to the When operator. /// or is null. public static QueryablePlan Then(this IQbservable source, Expression> selector) { if (source == null) throw new ArgumentNullException("source"); if (selector == null) throw new ArgumentNullException("selector"); return new QueryablePlan( Expression.Call( null, #if CRIPPLED_REFLECTION InfoOf(() => Qbservable.Then(default(IQbservable), default(Expression>))), #else ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource), typeof(TResult)), #endif source.Expression, selector ) ); } /// /// Joins together the results from several patterns. /// /// The type of the elements in the result sequence, obtained from the specified patterns. /// Query provider used to construct the IQbservable<T> data source. /// A series of plans created by use of the Then operator on patterns. /// An observable sequence with the results from matching several patterns. /// or is null. public static IQbservable When(this IQbservableProvider provider, params QueryablePlan[] plans) { if (provider == null) throw new ArgumentNullException("provider"); if (plans == null) throw new ArgumentNullException("plans"); return provider.CreateQuery( Expression.Call( null, #if CRIPPLED_REFLECTION InfoOf(() => Qbservable.When(default(IQbservableProvider), default(QueryablePlan[]))), #else ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TResult)), #endif Expression.Constant(provider, typeof(IQbservableProvider)), Expression.NewArrayInit( typeof(QueryablePlan), plans.Select(p => p.Expression) ) ) ); } /// /// Joins together the results from several patterns. /// /// The type of the elements in the result sequence, obtained from the specified patterns. /// Query provider used to construct the IQbservable<T> data source. /// A series of plans created by use of the Then operator on patterns. /// An observable sequence with the results form matching several patterns. /// or is null. public static IQbservable When(this IQbservableProvider provider, IEnumerable> plans) { if (provider == null) throw new ArgumentNullException("provider"); if (plans == null) throw new ArgumentNullException("plans"); return provider.CreateQuery( Expression.Call( null, #if CRIPPLED_REFLECTION InfoOf(() => Qbservable.When(default(IQbservableProvider), default(IEnumerable>))), #else ((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TResult)), #endif Expression.Constant(provider, typeof(IQbservableProvider)), Expression.Constant(plans, typeof(IEnumerable>)) ) ); } } } #pragma warning restore 1591