BaseResolve_Property.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Reflection;
  6. using System.Text;
  7. namespace SqlSugar
  8. {
  9. public partial class BaseResolve
  10. {
  11. #region Property
  12. protected Expression Expression { get; set; }
  13. protected Expression ExactExpression { get; set; }
  14. public ExpressionContext Context { get; set; }
  15. public bool? IsLeft { get; set; }
  16. public int ContentIndex { get { return this.Context.Index; } }
  17. public int Index { get; set; }
  18. public ExpressionParameter BaseParameter { get; set; }
  19. #endregion
  20. #region Dictionary
  21. private Dictionary<string, string> GetMappingColumns(Expression currentExpression)
  22. {
  23. Dictionary<string, string> result = new Dictionary<string, string>();
  24. if (currentExpression == null)
  25. {
  26. return result;
  27. }
  28. List<Type> types = new List<Type>();
  29. int i = 0;
  30. if (currentExpression is NewExpression)
  31. {
  32. i = (currentExpression as NewExpression).Arguments.Count;
  33. foreach (var item in (currentExpression as NewExpression).Arguments)
  34. {
  35. if (item.Type.IsClass())
  36. {
  37. types.Add(item.Type);
  38. }
  39. }
  40. }
  41. else if (currentExpression is MemberInitExpression)
  42. {
  43. i = (currentExpression as MemberInitExpression).Bindings.Count;
  44. foreach (var item in (currentExpression as MemberInitExpression).Bindings)
  45. {
  46. MemberAssignment memberAssignment = (MemberAssignment)item;
  47. if (memberAssignment.Expression.Type.IsClass())
  48. {
  49. types.Add(memberAssignment.Expression.Type);
  50. }
  51. }
  52. }
  53. if (types.Count == i && (types.Count == types.Distinct().Count()))
  54. {
  55. return result;
  56. }
  57. var array = currentExpression.ToString().Split(',');
  58. foreach (var item in array)
  59. {
  60. var itemArray = item.Split('=').ToArray();
  61. var last = itemArray.Last().Trim().Split('.').First().TrimEnd(')').TrimEnd('}');
  62. var first = itemArray.First().Trim();
  63. if (first.Contains("{"))
  64. {
  65. first = first.Split('{').Last().Trim();
  66. }
  67. if (first.Contains("("))
  68. {
  69. first = first.Split('(').Last().Trim();
  70. }
  71. if (!result.ContainsKey(first))
  72. {
  73. result.Add(first, last);
  74. }
  75. else
  76. {
  77. //future
  78. }
  79. }
  80. return result; ;
  81. }
  82. protected static Dictionary<string, string> MethodMapping = new Dictionary<string, string>() {
  83. { "ToString","ToString"},
  84. { "ToInt32","ToInt32"},
  85. { "ToInt16","ToInt32"},
  86. { "ToInt64","ToInt64"},
  87. { "ToDecimal","ToDecimal"},
  88. { "ToDateTime","ToDate"},
  89. { "ToBoolean","ToBool"},
  90. { "ToDouble","ToDouble"},
  91. { "Length","Length"},
  92. { "Replace","Replace"},
  93. { "Contains","Contains"},
  94. { "ContainsArray","ContainsArray"},
  95. { "EndsWith","EndsWith"},
  96. { "StartsWith","StartsWith"},
  97. { "HasValue","HasValue"},
  98. { "Trim","Trim"},
  99. { "Equals","Equals"},
  100. { "ToLower","ToLower"},
  101. { "ToUpper","ToUpper"},
  102. { "Substring","Substring"},
  103. { "DateAdd","DateAdd"},
  104. { "CompareTo","CompareTo"}
  105. };
  106. protected static Dictionary<string, DateType> MethodTimeMapping = new Dictionary<string, DateType>() {
  107. { "AddYears",DateType.Year},
  108. { "AddMonths",DateType.Month},
  109. { "AddDays",DateType.Day},
  110. { "AddHours",DateType.Hour},
  111. { "AddMinutes",DateType.Minute},
  112. { "AddSeconds",DateType.Second},
  113. { "AddMilliseconds",DateType.Millisecond}
  114. };
  115. #endregion
  116. }
  117. }