| 1 |
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. |
| 2 |
|
| 3 |
#if !NO_EXPRESSIONS |
| 4 |
using System.Collections.Generic; |
| 5 |
using System.Linq; |
| 6 |
using System.Linq.Expressions; |
| 7 |
using System.Reflection; |
| 8 |
|
| 9 |
namespace System.Reactive.Linq |
| 10 |
{ |
| 11 |
/// <summary> |
| 12 |
/// Provides a set of static methods for writing queries over observable sequences, allowing translation to a target query language. |
| 13 |
/// </summary> |
| 14 |
[LocalQueryMethodImplementationType(typeof(ObservableEx))] |
| 15 |
public static partial class QbservableEx |
| 16 |
{ |
| 17 |
internal static Expression GetSourceExpression<TSource>(IObservable<TSource> source) |
| 18 |
{ |
| 19 |
var q = source as IQbservable<TSource>; |
| 20 |
if (q != null) |
| 21 |
return q.Expression; |
| 22 |
|
| 23 |
return Expression.Constant(source, typeof(IObservable<TSource>)); |
| 24 |
} |
| 25 |
|
| 26 |
internal static Expression GetSourceExpression<TSource>(IEnumerable<TSource> source) |
| 27 |
{ |
| 28 |
var q = source as IQueryable<TSource>; |
| 29 |
if (q != null) |
| 30 |
return q.Expression; |
| 31 |
|
| 32 |
return Expression.Constant(source, typeof(IEnumerable<TSource>)); |
| 33 |
} |
| 34 |
|
| 35 |
internal static Expression GetSourceExpression<TSource>(IObservable<TSource>[] sources) |
| 36 |
{ |
| 37 |
return Expression.NewArrayInit( |
| 38 |
typeof(IObservable<TSource>), |
| 39 |
sources.Select(source => GetSourceExpression(source)) |
| 40 |
); |
| 41 |
} |
| 42 |
|
| 43 |
internal static Expression GetSourceExpression<TSource>(IEnumerable<TSource>[] sources) |
| 44 |
{ |
| 45 |
return Expression.NewArrayInit( |
| 46 |
typeof(IEnumerable<TSource>), |
| 47 |
sources.Select(source => GetSourceExpression(source)) |
| 48 |
); |
| 49 |
} |
| 50 |
|
| 51 |
internal static MethodInfo InfoOf<R>(Expression<Func<R>> f) |
| 52 |
{ |
| 53 |
return ((MethodCallExpression)f.Body).Method; |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
#endif |