Browse Source

Code optimization

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
0de0aa0a09
  1. 8
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionConst.cs
  2. 34
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs
  3. 20
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BinaryExpressionResolve.cs
  4. 6
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs

8
Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionConst.cs

@ -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";
}
}

34
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs

@ -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");
}
}

20
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BinaryExpressionResolve.cs

@ -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 + " ");
}
}
}

6
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs

@ -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
{

Loading…
Cancel
Save