// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
#if !NO_EXPRESSIONS
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
namespace System.Reactive.Linq
{
///
/// Provides a set of static methods for writing queries over observable sequences, allowing translation to a target query language.
///
[LocalQueryMethodImplementationType(typeof(ObservableEx))]
public static partial class QbservableEx
{
internal static Expression GetSourceExpression(IObservable source)
{
var q = source as IQbservable;
if (q != null)
return q.Expression;
return Expression.Constant(source, typeof(IObservable));
}
internal static Expression GetSourceExpression(IEnumerable source)
{
var q = source as IQueryable;
if (q != null)
return q.Expression;
return Expression.Constant(source, typeof(IEnumerable));
}
internal static Expression GetSourceExpression(IObservable[] sources)
{
return Expression.NewArrayInit(
typeof(IObservable),
sources.Select(source => GetSourceExpression(source))
);
}
internal static Expression GetSourceExpression(IEnumerable[] sources)
{
return Expression.NewArrayInit(
typeof(IEnumerable),
sources.Select(source => GetSourceExpression(source))
);
}
internal static MethodInfo InfoOf(Expression> f)
{
return ((MethodCallExpression)f.Body).Method;
}
}
}
#endif