﻿// Decompiled with JetBrains decompiler
// Type: System.Web.UI.WebControls.QueryableHelpers
// Assembly: System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// MVID: 7E68A73E-4066-4F24-AB0A-F147209F50EC
// Assembly location: C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Web.dll

using System;
using System.Linq;
using System.Web.Util;

namespace System.Web.UI.WebControls
{
  internal static class QueryableHelpers
  {
    public static IQueryable<T> SortandPageHelper<T>(IQueryable<T> queryable, int? startRowIndex, int? maxRowIndex, string sortExpression) where T : class
    {
      if (queryable == null)
        throw new ArgumentNullException("queryable");
      if (!string.IsNullOrEmpty(sortExpression))
        queryable = QueryExtensions.SortBy<T>(queryable, sortExpression);
      if (startRowIndex.HasValue && maxRowIndex.HasValue)
        queryable = Queryable.Take<T>(Queryable.Skip<T>(queryable, startRowIndex.Value), maxRowIndex.Value);
      return queryable;
    }

    public static int CountHelper<T>(IQueryable<T> queryable) where T : class
    {
      if (queryable == null)
        throw new ArgumentNullException("queryable");
      return Queryable.Count<T>(queryable);
    }

    public static bool IsOrderingMethodFound<T>(IQueryable<T> queryable) where T : class
    {
      return OrderingMethodFinder.OrderMethodExists(queryable.Expression);
    }
  }
}
