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.

172 lines
5.5 KiB

2 years ago
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Text;
  4. namespace SqlSugar
  5. {
  6. public class ExpressionResult
  7. {
  8. public bool IsLockCurrentParameter { get; set; }
  9. public bool IsUpper { get; set; }
  10. private ExpressionParameter _CurrentParameter;
  11. public ExpressionParameter CurrentParameter
  12. {
  13. get
  14. {
  15. return this._CurrentParameter;
  16. }
  17. set
  18. {
  19. Check.Exception(value != null && IsLockCurrentParameter, "CurrentParameter is locked.");
  20. this._CurrentParameter = value;
  21. this.IsLockCurrentParameter = false;
  22. }
  23. }
  24. #region constructor
  25. private ExpressionResult()
  26. {
  27. }
  28. public ExpressionResult(ResolveExpressType resolveExpressType)
  29. {
  30. this._ResolveExpressType = resolveExpressType;
  31. }
  32. #endregion
  33. #region Fields
  34. private ResolveExpressType _ResolveExpressType;
  35. private StringBuilder _Result;
  36. #endregion
  37. #region properties
  38. private StringBuilder Result
  39. {
  40. get
  41. {
  42. if (_Result == null) _Result = new StringBuilder();
  43. return _Result;
  44. }
  45. set
  46. {
  47. _Result = value;
  48. }
  49. }
  50. public bool LastCharIsSpace{
  51. get {
  52. if (_Result == null|| _Result.Length==0) return true;
  53. return _Result.ToString().Last() == UtilConstants.SpaceChar;
  54. }
  55. }
  56. #endregion
  57. public string GetString()
  58. {
  59. if (_Result == null) return null;
  60. if (IsUpper)
  61. return _Result.ToString().ToUpper().TrimEnd(',');
  62. else
  63. return _Result.ToString().TrimEnd(',');
  64. }
  65. #region functions
  66. public string[] GetResultArray()
  67. {
  68. if (this._Result == null) return null;
  69. if (IsUpper)
  70. return this.Result.ToString().ToUpper().TrimEnd(',').Split(',');
  71. else
  72. return this.Result.ToString().TrimEnd(',').Split(',');
  73. }
  74. public string GetResultString()
  75. {
  76. if (this._Result == null) return null;
  77. if (this._ResolveExpressType.IsIn(ResolveExpressType.SelectMultiple, ResolveExpressType.SelectSingle))
  78. {
  79. return this.Result.ToString().TrimEnd(',');
  80. }
  81. if (IsUpper)
  82. return this.Result.ToString().ToUpper();
  83. else
  84. return this.Result.ToString();
  85. }
  86. public void TrimEnd()
  87. {
  88. if (this._Result == null) return;
  89. this.Result = this.Result.Remove(this.Result.Length - 1, 1);
  90. }
  91. public bool Contains(string value)
  92. {
  93. if (this.Result.Equals(value)) return true;
  94. return (this.Result.ToString().Contains(value));
  95. }
  96. internal void Insert(int index, string value)
  97. {
  98. if (this.Result == null) this.Result.Append(value);
  99. this.Result.Insert(index, value);
  100. }
  101. public void Append(object parameter)
  102. {
  103. if (this.CurrentParameter.HasValue() && this.CurrentParameter.AppendType.IsIn(ExpressionResultAppendType.AppendTempDate))
  104. {
  105. this.CurrentParameter.CommonTempData = parameter;
  106. return;
  107. }
  108. switch (this._ResolveExpressType)
  109. {
  110. case ResolveExpressType.ArraySingle:
  111. case ResolveExpressType.ArrayMultiple:
  112. case ResolveExpressType.SelectSingle:
  113. case ResolveExpressType.SelectMultiple:
  114. case ResolveExpressType.Update:
  115. parameter = parameter + ",";
  116. break;
  117. case ResolveExpressType.WhereSingle:
  118. break;
  119. case ResolveExpressType.WhereMultiple:
  120. break;
  121. case ResolveExpressType.FieldSingle:
  122. break;
  123. case ResolveExpressType.FieldMultiple:
  124. break;
  125. default:
  126. break;
  127. }
  128. this.Result.Append(parameter);
  129. }
  130. public void AppendFormat(string parameter, params object[] orgs)
  131. {
  132. if (this.CurrentParameter.HasValue() && this.CurrentParameter.AppendType.IsIn(ExpressionResultAppendType.AppendTempDate))
  133. {
  134. this.CurrentParameter.CommonTempData = new KeyValuePair<string, object[]>(parameter, orgs);
  135. return;
  136. }
  137. switch (this._ResolveExpressType)
  138. {
  139. case ResolveExpressType.SelectSingle:
  140. case ResolveExpressType.SelectMultiple:
  141. parameter = parameter + ",";
  142. break;
  143. case ResolveExpressType.WhereSingle:
  144. break;
  145. case ResolveExpressType.WhereMultiple:
  146. break;
  147. case ResolveExpressType.FieldSingle:
  148. break;
  149. case ResolveExpressType.FieldMultiple:
  150. break;
  151. default:
  152. break;
  153. }
  154. this.Result.AppendFormat(parameter, orgs);
  155. }
  156. public void Replace(string parameter, string newValue)
  157. {
  158. this.Result.Replace(parameter, newValue);
  159. }
  160. #endregion
  161. }
  162. }