PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/Atlassian.Jira/Linq/ExpressionTreeModifier.cs

https://bitbucket.org/yyo/atlassian.net-sdk-v2.0
C# | 46 lines | 40 code | 6 blank | 0 comment | 14 complexity | 599b071685a57d0910a222a9ad75352c MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. namespace Atlassian.Jira.Linq
  7. {
  8. internal class ExpressionTreeModifier: ExpressionVisitor
  9. {
  10. private readonly IQueryable<Issue> _queryableIssues;
  11. public ExpressionTreeModifier(IQueryable<Issue> queryableIssues)
  12. {
  13. _queryableIssues = queryableIssues;
  14. }
  15. protected override Expression VisitConstant(ConstantExpression node)
  16. {
  17. if (node.Type == typeof(JiraQueryable<Issue>))
  18. {
  19. return Expression.Constant(_queryableIssues);
  20. }
  21. else
  22. {
  23. return node;
  24. }
  25. }
  26. protected override Expression VisitMethodCall(MethodCallExpression node)
  27. {
  28. if (node.Method.Name == "Where"
  29. || node.Method.Name == "Take"
  30. || node.Method.Name == "OrderBy"
  31. || node.Method.Name == "OrderByDescending"
  32. || node.Method.Name == "ThenBy"
  33. || node.Method.Name == "ThenByDescending")
  34. {
  35. return Expression.Constant(_queryableIssues);
  36. }
  37. return base.VisitMethodCall(node);
  38. }
  39. }
  40. }