You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
2.4 KiB

2 years ago
  1. using System.Linq.Expressions;
  2. namespace SqlSugar
  3. {
  4. public class NewExpressionResolve : BaseResolve
  5. {
  6. public NewExpressionResolve(ExpressionParameter parameter) : base(parameter)
  7. {
  8. var expression = base.Expression as NewExpression;
  9. Check.Exception(expression.Type == UtilConstants.GuidType, "Not Support new Guid(), Use Guid.New()");
  10. switch (parameter.Context.ResolveType)
  11. {
  12. case ResolveExpressType.WhereSingle:
  13. Check.ThrowNotSupportedException(expression.ToString());
  14. break;
  15. case ResolveExpressType.WhereMultiple:
  16. Check.ThrowNotSupportedException(expression.ToString());
  17. break;
  18. case ResolveExpressType.SelectSingle:
  19. Check.Exception(expression.Type == UtilConstants.DateType, "ThrowNotSupportedException {0} ",expression.ToString());
  20. Select(expression, parameter, true);
  21. break;
  22. case ResolveExpressType.SelectMultiple:
  23. Check.Exception(expression.Type == UtilConstants.DateType, "ThrowNotSupportedException {0} ", expression.ToString());
  24. Select(expression, parameter, false);
  25. break;
  26. case ResolveExpressType.FieldSingle:
  27. Check.ThrowNotSupportedException(expression.ToString());
  28. break;
  29. case ResolveExpressType.FieldMultiple:
  30. case ResolveExpressType.ArrayMultiple:
  31. case ResolveExpressType.ArraySingle:
  32. foreach (var item in expression.Arguments)
  33. {
  34. base.Expression = item;
  35. base.Start();
  36. }
  37. break;
  38. default:
  39. break;
  40. }
  41. }
  42. private void Select(NewExpression expression, ExpressionParameter parameter, bool isSingle)
  43. {
  44. if (expression.Arguments != null)
  45. {
  46. var i = 0;
  47. foreach (var item in expression.Arguments)
  48. {
  49. var memberName = expression.Members[i].Name;
  50. ++i;
  51. ResolveNewExpressions(parameter, item, memberName);
  52. }
  53. }
  54. }
  55. }
  56. }