From 3103d79485bdae1c54e22f6acd77cd52ca328d39 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Fri, 25 Aug 2017 22:00:42 +0800 Subject: [PATCH] Code optimization --- .../ExpressionsToSql/Common/ErrorMessage.cs | 33 +++++++++++++++++++ .../Common/ExpressionConst.cs | 7 ---- .../Common/ExpressionErrorMessage.cs | 33 ------------------- .../ExpressionsToSql/Common/ExpressionTool.cs | 2 +- .../MethodCallExpressionResolve.cs | 2 +- Src/Asp.Net/SqlSugar/SqlSugar.csproj | 2 +- 6 files changed, 36 insertions(+), 43 deletions(-) create mode 100644 Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ErrorMessage.cs delete mode 100644 Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionErrorMessage.cs diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ErrorMessage.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ErrorMessage.cs new file mode 100644 index 000000000..b8314cb20 --- /dev/null +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ErrorMessage.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +namespace SqlSugar +{ + internal static partial class ErrorMessage + { + internal static string OperatorError + { + get + { + return ErrorMessage.GetThrowMessage("Lambda parsing error: {0} does not support the operator to find!","拉姆达解析出错:不支持{0}此种运算符查找!"); + } + } + internal static string ExpFileldError + { + get + { + return ErrorMessage.GetThrowMessage("Expression format error, correct format: it=>it.fieldName","表达示格式错误,正确格式: it=>it.fieldName"); + } + } + + internal static string MethodError + { + get + { + return ErrorMessage.GetThrowMessage("Expression parsing does not support the current function {0}. There are many functions available in the SqlFunc class, for example, it=>SqlFunc.HasValue(it.Id)", "拉姆达解析不支持当前函数{0},SqlFunc这个类里面有大量函数可用,也许有你想要的,例如: it=>SqlFunc.HasValue(it.Id)"); + } + } + } +} diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionConst.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionConst.cs index 77d61a8f0..7b7ea6df3 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionConst.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionConst.cs @@ -19,12 +19,5 @@ namespace SqlSugar public readonly static Type MemberExpressionType = typeof(MemberExpression); public readonly static Type ConstantExpressionType = typeof(ConstantExpression); public readonly static Type StringType = typeof(string); - - internal static string GetThrowMessage(string enMessage, string cnMessage, params string[] args) - { - List formatArgs = new List() { enMessage, cnMessage }; - formatArgs.AddRange(args); - return string.Format("\r\n English Message : {0}\r\n Chinese Message : {1}", formatArgs.ToArray()); - } } } diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionErrorMessage.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionErrorMessage.cs deleted file mode 100644 index 0ec70f3c7..000000000 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionErrorMessage.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace SqlSugar -{ - internal class ExpressionErrorMessage - { - internal static string OperatorError - { - get - { - return ExpressionConst.GetThrowMessage("Lambda parsing error: {0} does not support the operator to find!","拉姆达解析出错:不支持{0}此种运算符查找!"); - } - } - internal static string ExpFileldError - { - get - { - return ExpressionConst.GetThrowMessage("Expression format error, correct format: it=>it.fieldName","表达示格式错误,正确格式: it=>it.fieldName"); - } - } - - internal static string MethodError - { - get - { - return ExpressionConst.GetThrowMessage("Expression parsing does not support the current function {0}. There are many functions available in the SqlFunc class, for example, it=>SqlFunc.HasValue(it.Id)", "拉姆达解析不支持当前函数{0},SqlFunc这个类里面有大量函数可用,也许有你想要的,例如: it=>SqlFunc.HasValue(it.Id)"); - } - } - } -} diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs index 47dba30ce..0941e6e6b 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs @@ -42,7 +42,7 @@ namespace SqlSugar case ExpressionType.MultiplyChecked: return "*"; default: - Check.ThrowNotSupportedException(string.Format(ExpressionErrorMessage.OperatorError, expressiontype.ToString())); + Check.ThrowNotSupportedException(string.Format(ErrorMessage.OperatorError, expressiontype.ToString())); return null; } } diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs index 503f919d2..862023227 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs @@ -427,7 +427,7 @@ namespace SqlSugar private void CheckMethod(MethodCallExpression expression) { - Check.Exception(expression.Method.ReflectedType().FullName != ExpressionConst.SqlFuncFullName, string.Format(ExpressionErrorMessage.MethodError, expression.Method.Name)); + Check.Exception(expression.Method.ReflectedType().FullName != ExpressionConst.SqlFuncFullName, string.Format(ErrorMessage.MethodError, expression.Method.Name)); } } } diff --git a/Src/Asp.Net/SqlSugar/SqlSugar.csproj b/Src/Asp.Net/SqlSugar/SqlSugar.csproj index 8278b5c4c..eb5804e17 100644 --- a/Src/Asp.Net/SqlSugar/SqlSugar.csproj +++ b/Src/Asp.Net/SqlSugar/SqlSugar.csproj @@ -167,7 +167,7 @@ - +