mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2026-02-26 05:32:53 +08:00
Code optimization
This commit is contained in:
@@ -7,13 +7,13 @@ namespace SqlSugar
|
||||
{
|
||||
internal class ExpressionConst
|
||||
{
|
||||
public const string Format4 = ")";
|
||||
public const string Format3 = "(";
|
||||
public const string Format0 = "{0}";
|
||||
public const string Format1 = "$__$";
|
||||
public const string Const = "Const";
|
||||
public const string FormatSymbol = "{0}";
|
||||
public const string RightParenthesis = ")";
|
||||
public const string LeftParenthesis = "(";
|
||||
public const string MethodConst = "MethodConst";
|
||||
public const string SqlFuncFullName = "SqlSugar.SqlFunc";
|
||||
public const string BinaryFormatString = " ( {0} {1} {2} ) ";
|
||||
public const string ExpressionReplace = "46450BDC-77B7-4025-B2A6-3F048CA85AD0";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,11 +113,11 @@ namespace SqlSugar
|
||||
Context.ParameterIndex++;
|
||||
if (isLeft == true)
|
||||
{
|
||||
appendValue += ExpressionConst.Format1 + parameter.BaseParameter.Index;
|
||||
appendValue += ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index;
|
||||
}
|
||||
if (this.Context.Result.Contains(ExpressionConst.Format0))
|
||||
if (this.Context.Result.Contains(ExpressionConst.FormatSymbol))
|
||||
{
|
||||
this.Context.Result.Replace(ExpressionConst.Format0, appendValue.ObjToString());
|
||||
this.Context.Result.Replace(ExpressionConst.FormatSymbol, appendValue.ObjToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -132,9 +132,9 @@ namespace SqlSugar
|
||||
if (parameter.CurrentExpression is MethodCallExpression)
|
||||
{
|
||||
var appendValue = value;
|
||||
if (this.Context.Result.Contains(ExpressionConst.Format0))
|
||||
if (this.Context.Result.Contains(ExpressionConst.FormatSymbol))
|
||||
{
|
||||
this.Context.Result.Replace(ExpressionConst.Format0, appendValue.ObjToString());
|
||||
this.Context.Result.Replace(ExpressionConst.FormatSymbol, appendValue.ObjToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -159,11 +159,11 @@ namespace SqlSugar
|
||||
appendValue = string.Format(" {0} ", appendValue);
|
||||
if (isLeft == true)
|
||||
{
|
||||
appendValue += ExpressionConst.Format1 + parameter.BaseParameter.Index;
|
||||
appendValue += ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index;
|
||||
}
|
||||
if (this.Context.Result.Contains(ExpressionConst.Format0))
|
||||
if (this.Context.Result.Contains(ExpressionConst.FormatSymbol))
|
||||
{
|
||||
this.Context.Result.Replace(ExpressionConst.Format0, appendValue);
|
||||
this.Context.Result.Replace(ExpressionConst.FormatSymbol, appendValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -186,11 +186,11 @@ namespace SqlSugar
|
||||
appendValue = string.Format(" {0} ", appendValue);
|
||||
if (isLeft == true)
|
||||
{
|
||||
appendValue += ExpressionConst.Format1 + parameter.BaseParameter.Index;
|
||||
appendValue += ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index;
|
||||
}
|
||||
if (this.Context.Result.Contains(ExpressionConst.Format0))
|
||||
if (this.Context.Result.Contains(ExpressionConst.FormatSymbol))
|
||||
{
|
||||
this.Context.Result.Replace(ExpressionConst.Format0, appendValue);
|
||||
this.Context.Result.Replace(ExpressionConst.FormatSymbol, appendValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -209,11 +209,11 @@ namespace SqlSugar
|
||||
appendValue = string.Format(" {0} ", appendValue);
|
||||
if (isLeft == true)
|
||||
{
|
||||
appendValue += ExpressionConst.Format1 + parameter.BaseParameter.Index;
|
||||
appendValue += ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index;
|
||||
}
|
||||
if (this.Context.Result.Contains(ExpressionConst.Format0))
|
||||
if (this.Context.Result.Contains(ExpressionConst.FormatSymbol))
|
||||
{
|
||||
this.Context.Result.Replace(ExpressionConst.Format0, appendValue);
|
||||
this.Context.Result.Replace(ExpressionConst.FormatSymbol, appendValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -226,7 +226,7 @@ namespace SqlSugar
|
||||
{
|
||||
if (isLeft == true)
|
||||
{
|
||||
this.Context.Result.Append(" " + ExpressionConst.Format1 + parameter.BaseParameter.Index);
|
||||
this.Context.Result.Append(" " + ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index);
|
||||
}
|
||||
}
|
||||
protected string AppendParameter(object paramterValue)
|
||||
@@ -238,14 +238,14 @@ namespace SqlSugar
|
||||
}
|
||||
protected void AppendNot(object Value)
|
||||
{
|
||||
var isAppend = !this.Context.Result.Contains(ExpressionConst.Format0);
|
||||
var isAppend = !this.Context.Result.Contains(ExpressionConst.FormatSymbol);
|
||||
if (isAppend)
|
||||
{
|
||||
this.Context.Result.Append("NOT");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Context.Result.Replace(ExpressionConst.Format0, "NOT");
|
||||
this.Context.Result.Replace(ExpressionConst.FormatSymbol, "NOT");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,15 +22,15 @@ namespace SqlSugar
|
||||
var lsrb = !leftIsBinary && rightBinary;
|
||||
var lbrb = rightBinary && leftIsBinary;
|
||||
var lsbs = !leftIsBinary && !rightBinary;
|
||||
var isAppend = !base.Context.Result.Contains(ExpressionConst.Format0);
|
||||
var isAppend = !base.Context.Result.Contains(ExpressionConst.FormatSymbol);
|
||||
if (isAppend)
|
||||
{
|
||||
base.Context.Result.Append(ExpressionConst.Format3);
|
||||
base.Context.Result.Append(ExpressionConst.Format0);
|
||||
base.Context.Result.Append(ExpressionConst.LeftParenthesis);
|
||||
base.Context.Result.Append(ExpressionConst.FormatSymbol);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.Context.Result.Replace(ExpressionConst.Format0, ExpressionConst.Format3 + ExpressionConst.Format0);
|
||||
base.Context.Result.Replace(ExpressionConst.FormatSymbol, ExpressionConst.LeftParenthesis + ExpressionConst.FormatSymbol);
|
||||
}
|
||||
parameter.LeftExpression = leftExpression;
|
||||
parameter.RightExpression = rightExpression;
|
||||
@@ -43,18 +43,18 @@ namespace SqlSugar
|
||||
base.IsLeft = null;
|
||||
if (lsbs && parameter.ValueIsNull)
|
||||
{
|
||||
base.Context.Result.Replace(ExpressionConst.Format1 + parameter.Index, isEqual ? "IS" : "IS NOT");
|
||||
base.Context.Result.Replace(ExpressionConst.Format1 + (parameter.Index+1), isEqual ? "IS" : "IS NOT");
|
||||
base.Context.Result.Replace(ExpressionConst.ExpressionReplace + parameter.Index, isEqual ? "IS" : "IS NOT");
|
||||
base.Context.Result.Replace(ExpressionConst.ExpressionReplace + (parameter.Index+1), isEqual ? "IS" : "IS NOT");
|
||||
}
|
||||
else
|
||||
{
|
||||
base.Context.Result.Replace(ExpressionConst.Format1 + parameter.Index, operatorValue);
|
||||
base.Context.Result.Replace(ExpressionConst.Format1 + (parameter.Index + 1), operatorValue);
|
||||
base.Context.Result.Replace(ExpressionConst.ExpressionReplace + parameter.Index, operatorValue);
|
||||
base.Context.Result.Replace(ExpressionConst.ExpressionReplace + (parameter.Index + 1), operatorValue);
|
||||
}
|
||||
base.Context.Result.Append(ExpressionConst.Format4);
|
||||
base.Context.Result.Append(ExpressionConst.RightParenthesis);
|
||||
if (parameter.BaseExpression is BinaryExpression && parameter.IsLeft == true)
|
||||
{
|
||||
base.Context.Result.Append(" " + ExpressionConst.Format1 + parameter.BaseParameter.Index + " ");
|
||||
base.Context.Result.Append(" " + ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index + " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,11 +176,11 @@ namespace SqlSugar
|
||||
fieldName = string.Format(" {0} ", fieldName);
|
||||
if (isLeft == true)
|
||||
{
|
||||
fieldName += ExpressionConst.Format1 + parameter.BaseParameter.Index;
|
||||
fieldName += ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index;
|
||||
}
|
||||
if (base.Context.Result.Contains(ExpressionConst.Format0))
|
||||
if (base.Context.Result.Contains(ExpressionConst.FormatSymbol))
|
||||
{
|
||||
base.Context.Result.Replace(ExpressionConst.Format0, fieldName);
|
||||
base.Context.Result.Replace(ExpressionConst.FormatSymbol, fieldName);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user