2 using System.Linq.Expressions;
3 using System.Reflection;
5 namespace System.Web.Util {
6 internal static class QueryableUtility {
7 private static readonly string[] _orderMethods = new[] { "OrderBy", "ThenBy", "OrderByDescending", "ThenByDescending" };
8 private static readonly MethodInfo[] _methods = typeof(Queryable).GetMethods(BindingFlags.Public | BindingFlags.Static);
10 private static MethodInfo GetQueryableMethod(Expression expression) {
11 if (expression.NodeType == ExpressionType.Call) {
12 var call = (MethodCallExpression)expression;
13 if (call.Method.IsStatic && call.Method.DeclaringType == typeof(Queryable)) {
14 return call.Method.GetGenericMethodDefinition();
20 public static bool IsQueryableMethod(Expression expression, string method) {
21 return _methods.Where(m => m.Name == method).Contains(GetQueryableMethod(expression));
24 public static bool IsOrderingMethod(Expression expression) {
25 return _orderMethods.Any(method => IsQueryableMethod(expression, method));