SubqueryRules.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Reflection;
  5. using System.Linq.Expressions;
  6. namespace System.Data.Linq {
  7. /// <summary>
  8. /// Encodes the rules for subqueries.
  9. /// </summary>
  10. static class SubqueryRules {
  11. /// <summary>
  12. /// This list of top-level methods that are supported in subqueries.
  13. /// </summary>
  14. /// <param name="mi"></param>
  15. /// <returns></returns>
  16. static internal bool IsSupportedTopLevelMethod(MethodInfo mi) {
  17. if (!IsSequenceOperatorCall(mi))
  18. return false;
  19. switch (mi.Name) {
  20. case "Where":
  21. case "OrderBy":
  22. case "OrderByDescending":
  23. case "ThenBy":
  24. case "ThenByDescending":
  25. case "Take":
  26. return true;
  27. }
  28. return false;
  29. }
  30. private static bool IsSequenceOperatorCall(MethodInfo mi) {
  31. Type declType = mi.DeclaringType;
  32. if (declType == typeof(System.Linq.Enumerable) ||
  33. declType == typeof(System.Linq.Queryable)) {
  34. return true;
  35. }
  36. return false;
  37. }
  38. }
  39. }