コード例 #1
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="expression">表达式</param>
 /// <param name="type">操作字符串</param>
 private void convertBinaryExpression(TmphConverter converter, TmphBinaryExpression binaryExpression, string type)
 {
     var stream = converter.Stream;
     TmphExpression left = binaryExpression.Left, right = binaryExpression.Right;
     stream.Write('(');
     if (left.IsSimple)
     {
         converters[(int)left.NodeType](converter, left);
         stream.Write('=');
         stream.Write('1');
     }
     else converters[(int)left.NodeType](converter, left);
     stream.Write(')');
     stream.WriteNotNull(type);
     stream.Write('(');
     if (right.IsSimple)
     {
         converters[(int)right.NodeType](converter, right);
         stream.Write('=');
         stream.Write('1');
     }
     else converters[(int)right.NodeType](converter, right);
     stream.Write(')');
 }
コード例 #2
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="expression">表达式</param>
 private void convertNotEqual(TmphConverter converter, TmphExpression expression)
 {
     var binaryExpression = (TmphBinaryExpression)expression;
     if (binaryExpression.Left.IsConstantNull)
     {
         var stream = converter.Stream;
         if (binaryExpression.Right.IsSimple)
         {
             converters[(int)binaryExpression.Right.NodeType](converter, binaryExpression.Right);
         }
         else
         {
             stream.Write('(');
             converters[(int)binaryExpression.Right.NodeType](converter, binaryExpression.Right);
             stream.Write(')');
         }
         stream.WriteNotNull(" is not null");
     }
     else if (binaryExpression.Right.IsConstantNull)
     {
         var stream = converter.Stream;
         if (binaryExpression.Left.IsSimple)
         {
             converters[(int)binaryExpression.Left.NodeType](converter, binaryExpression.Left);
         }
         else
         {
             stream.Write('(');
             converters[(int)binaryExpression.Left.NodeType](converter, binaryExpression.Left);
             stream.Write(')');
         }
         stream.WriteNotNull(" is not null");
     }
     else convertNotEqual(converter, (TmphBinaryExpression)expression);
 }
コード例 #3
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="expression">表达式</param>
 /// <param name="char1">操作字符1</param>
 /// <param name="char2">操作字符2</param>
 protected void convertBinaryExpression(TmphConverter converter, TmphBinaryExpression binaryExpression,
     char char1, char char2 = ' ')
 {
     var stream = converter.Stream;
     TmphExpression left = binaryExpression.Left, right = binaryExpression.Right;
     if (left.IsSimple)
     {
         converters[(int)left.NodeType](converter, left);
     }
     else
     {
         stream.Write('(');
         converters[(int)left.NodeType](converter, left);
         stream.Write(')');
     }
     stream.Write(char1);
     stream.Write(char2);
     if (right.IsSimple)
     {
         converters[(int)right.NodeType](converter, right);
     }
     else
     {
         stream.Write('(');
         converters[(int)right.NodeType](converter, right);
         stream.Write(')');
     }
 }
コード例 #4
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="unaryExpression">表达式</param>
 private void convertConvert(TmphConverter converter, TmphExpression expression)
 {
     var convertExpression = (TmphConvertExpression)expression;
     converter.Stream.WriteNotNull("cast(");
     converters[(int)convertExpression.Expression.NodeType](converter, convertExpression.Expression);
     converter.Stream.WriteNotNull(" as ");
     converter.Stream.WriteNotNull(convertExpression.ConvertType.formCSharpType().ToString());
     converter.Stream.Write(')');
 }
コード例 #5
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="expression">表达式</param>
 private void convertCall(TmphConverter converter, TmphExpression expression)
 {
     var methodCallExpression = (TmphMethodCallExpression)expression;
     var stream = converter.Stream;
     stream.WriteNotNull(methodCallExpression.Method.Name);
     stream.Write('(');
     if (methodCallExpression.Arguments != null)
     {
         var isNext = false;
         foreach (var argumentExpression in methodCallExpression.Arguments)
         {
             if (isNext) stream.Write(',');
             converters[(int)argumentExpression.NodeType](converter, argumentExpression);
             isNext = true;
         }
     }
     stream.Write(')');
 }
コード例 #6
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="expression">表达式</param>
 private void convertPropertyAccess(TmphConverter converter, TmphExpression expression)
 {
     var propertyExpression = (TmphPropertyExpression)expression;
     convertMemberAccess(converter, propertyExpression, propertyExpression.PropertyInfo.Name);
 }
コード例 #7
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="unaryExpression">表达式</param>
 private void convertUnaryPlus(TmphConverter converter, TmphExpression expression)
 {
     expression = ((TmphUnaryExpression)expression).Expression;
     converter.Stream.WriteNotNull("+(");
     converters[(int)expression.NodeType](converter, expression);
     converter.Stream.Write(')');
 }
コード例 #8
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="expression">表达式</param>
 private void convertDivide(TmphConverter converter, TmphExpression expression)
 {
     convertBinaryExpression(converter, (TmphBinaryExpression)expression, '/');
 }
コード例 #9
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="expression">表达式</param>
 private void convertModulo(TmphConverter converter, TmphExpression expression)
 {
     convertBinaryExpression(converter, (TmphBinaryExpression)expression, '%');
 }
コード例 #10
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="expression">表达式</param>
 private void convertSubtract(TmphConverter converter, TmphExpression expression)
 {
     convertBinaryExpression(converter, (TmphBinaryExpression)expression, '-');
 }
コード例 #11
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="expression">表达式</param>
 private void convertMultiply(TmphConverter converter, TmphExpression expression)
 {
     convertBinaryExpression(converter, (TmphBinaryExpression)expression, '*');
 }
コード例 #12
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="expression">表达式</param>
 private void convertLessThanOrEqual(TmphConverter converter, TmphExpression expression)
 {
     convertBinaryExpression(converter, (TmphBinaryExpression)expression, '<', '=');
 }
コード例 #13
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="expression">表达式</param>
 private void convertGreaterThan(TmphConverter converter, TmphExpression expression)
 {
     convertBinaryExpression(converter, (TmphBinaryExpression)expression, '>');
 }
コード例 #14
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="expression">表达式</param>
 protected virtual void convertNotEqual(TmphConverter converter, TmphBinaryExpression expression)
 {
     convertBinaryExpression(converter, expression, '<', '>');
 }
コード例 #15
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="expression">表达式</param>
 /// <param name="name">成员名称</param>
 private void convertMemberAccess(TmphConverter converter, TmphMemberExpression memberExpression, string name)
 {
     if (memberExpression.Expression.GetType() == typeof(TmphParameterExpression))
     {
         if (converter.FirstMemberName == null) converter.FirstMemberName = name;
         converter.Stream.WriteNotNull(name);
     }
     else TmphLog.Error.Throw("未知成员表达式类型 " + memberExpression.Expression.GetType().Name, false, true);
 }
コード例 #16
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="expression">表达式</param>
 private void convertPower(TmphConverter converter, TmphExpression expression)
 {
     TmphLog.Error.Throw(TmphLog.TmphExceptionType.ErrorOperation);
 }
コード例 #17
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="expression">表达式</param>
 private void convertFieldAccess(TmphConverter converter, TmphExpression expression)
 {
     var fieldExpression = (TmphFieldExpression)expression;
     convertMemberAccess(converter, fieldExpression, fieldExpression.FieldInfo.Name);
 }
コード例 #18
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="expression">表达式</param>
 private void convertAnd(TmphConverter converter, TmphExpression expression)
 {
     convertBinaryExpression(converter, (TmphBinaryExpression)expression, '&');
 }
コード例 #19
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="unaryExpression">表达式</param>
 private void convertUnbox(TmphConverter converter, TmphExpression expression)
 {
     expression = ((TmphUnaryExpression)expression).Expression;
     if (expression.IsSimple)
     {
         converters[(int)expression.NodeType](converter, expression);
     }
     else
     {
         converter.Stream.Write('(');
         converters[(int)expression.NodeType](converter, expression);
         converter.Stream.Write(')');
     }
 }
コード例 #20
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="expression">表达式</param>
 private void convertExclusiveOr(TmphConverter converter, TmphExpression expression)
 {
     convertBinaryExpression(converter, (TmphBinaryExpression)expression, '^');
 }
コード例 #21
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="unaryExpression">表达式</param>
 private void convertIsFalse(TmphConverter converter, TmphExpression expression)
 {
     expression = ((TmphUnaryExpression)expression).Expression;
     if (expression.IsSimple)
     {
         converters[(int)expression.NodeType](converter, expression);
         converter.Stream.WriteNotNull("=0");
     }
     else
     {
         converter.Stream.Write('(');
         converters[(int)expression.NodeType](converter, expression);
         converter.Stream.WriteNotNull(")=0");
     }
 }
コード例 #22
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="expression">表达式</param>
 private void convertLeftShift(TmphConverter converter, TmphExpression expression)
 {
     convertBinaryExpression(converter, (TmphBinaryExpression)expression, '<', '<');
 }
コード例 #23
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="expression">表达式</param>
 private void convertConditional(TmphConverter converter, TmphExpression expression)
 {
     var stream = converter.Stream;
     var conditionalExpression = (TmphConditionalExpression)expression;
     TmphExpression test = conditionalExpression.Test,
         ifTrue = conditionalExpression.IfTrue,
         ifFalse = conditionalExpression.IfFalse;
     stream.WriteNotNull("case when ");
     if (test.IsSimple)
     {
         converters[(int)test.NodeType](converter, test);
         stream.Write('=');
         stream.Write('1');
     }
     else converters[(int)test.NodeType](converter, test);
     stream.WriteNotNull(" then ");
     if (ifTrue.IsSimple) converters[(int)ifTrue.NodeType](converter, ifTrue);
     else
     {
         stream.Write('(');
         converters[(int)ifTrue.NodeType](converter, ifTrue);
         stream.Write(')');
     }
     stream.WriteNotNull(" else ");
     if (ifFalse.IsSimple) converters[(int)ifFalse.NodeType](converter, ifFalse);
     else
     {
         stream.Write('(');
         converters[(int)ifFalse.NodeType](converter, ifFalse);
         stream.Write(')');
     }
     stream.WriteNotNull(" end");
 }
コード例 #24
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="expression">表达式</param>
 private void convertRightShift(TmphConverter converter, TmphExpression expression)
 {
     convertBinaryExpression(converter, (TmphBinaryExpression)expression, '>', '>');
 }
コード例 #25
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="expression">表达式</param>
 private void convertOrElse(TmphConverter converter, TmphExpression expression)
 {
     convertBinaryExpression(converter, (TmphBinaryExpression)expression, "or");
 }
コード例 #26
0
 /// <summary>
 ///     转换表达式
 /// </summary>
 /// <param name="converter">表达式转换器</param>
 /// <param name="expression">表达式</param>
 private void convertAndAlso(TmphConverter converter, TmphExpression expression)
 {
     convertBinaryExpression(converter, (TmphBinaryExpression)expression, "and");
 }