Imported Upstream version 4.6.0.125

Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-08-03 10:59:49 +00:00
parent a569aebcfd
commit e79aa3c0ed
17047 changed files with 3137615 additions and 392334 deletions

View File

@ -0,0 +1,29 @@
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
namespace System.Web.Util {
internal static class QueryableUtility {
private static readonly string[] _orderMethods = new[] { "OrderBy", "ThenBy", "OrderByDescending", "ThenByDescending" };
private static readonly MethodInfo[] _methods = typeof(Queryable).GetMethods(BindingFlags.Public | BindingFlags.Static);
private static MethodInfo GetQueryableMethod(Expression expression) {
if (expression.NodeType == ExpressionType.Call) {
var call = (MethodCallExpression)expression;
if (call.Method.IsStatic && call.Method.DeclaringType == typeof(Queryable)) {
return call.Method.GetGenericMethodDefinition();
}
}
return null;
}
public static bool IsQueryableMethod(Expression expression, string method) {
return _methods.Where(m => m.Name == method).Contains(GetQueryableMethod(expression));
}
public static bool IsOrderingMethod(Expression expression) {
return _orderMethods.Any(method => IsQueryableMethod(expression, method));
}
}
}