Beispiel #1
0
        internal override void Decompile(CodeExpression expression, StringBuilder stringBuilder, CodeExpression parentExpression)
        {
            CodeCastExpression childExpr   = (CodeCastExpression)expression;
            CodeExpression     expression3 = childExpr.Expression;

            if (expression3 == null)
            {
                RuleEvaluationException exception = new RuleEvaluationException(Messages.NullCastExpr);
                exception.Data["ErrorObject"] = childExpr;
                throw exception;
            }
            if (childExpr.TargetType == null)
            {
                RuleEvaluationException exception2 = new RuleEvaluationException(Messages.NullCastType);
                exception2.Data["ErrorObject"] = childExpr;
                throw exception2;
            }
            bool flag = RuleDecompiler.MustParenthesize(childExpr, parentExpression);

            if (flag)
            {
                stringBuilder.Append("(");
            }
            stringBuilder.Append("(");
            RuleDecompiler.DecompileType(stringBuilder, childExpr.TargetType);
            stringBuilder.Append(")");
            RuleExpressionWalker.Decompile(stringBuilder, expression3, childExpr);
            if (flag)
            {
                stringBuilder.Append(")");
            }
        }
        internal override void Decompile(CodeExpression expression, StringBuilder stringBuilder, CodeExpression parentExpression)
        {
            CodeObjectCreateExpression childExpr = (CodeObjectCreateExpression)expression;
            bool flag = RuleDecompiler.MustParenthesize(childExpr, parentExpression);

            if (flag)
            {
                stringBuilder.Append("(");
            }
            stringBuilder.Append("new ");
            RuleDecompiler.DecompileType(stringBuilder, childExpr.CreateType);
            stringBuilder.Append('(');
            for (int i = 0; i < childExpr.Parameters.Count; i++)
            {
                CodeExpression expression3 = childExpr.Parameters[i];
                if (expression3 == null)
                {
                    RuleEvaluationException exception = new RuleEvaluationException(string.Format(CultureInfo.CurrentCulture, Messages.NullConstructorTypeParameter, new object[] { i.ToString(CultureInfo.CurrentCulture), childExpr.CreateType }));
                    exception.Data["ErrorObject"] = childExpr;
                    throw exception;
                }
                if (i > 0)
                {
                    stringBuilder.Append(", ");
                }
                RuleExpressionWalker.Decompile(stringBuilder, expression3, null);
            }
            stringBuilder.Append(')');
            if (flag)
            {
                stringBuilder.Append(")");
            }
        }
        internal override void Decompile(CodeExpression expression, StringBuilder stringBuilder, CodeExpression parentExpression)
        {
            string str3;
            bool   flag = false;
            CodeBinaryOperatorExpression childExpr = (CodeBinaryOperatorExpression)expression;

            if (childExpr.Left == null)
            {
                RuleEvaluationException exception = new RuleEvaluationException(string.Format(CultureInfo.CurrentCulture, Messages.NullBinaryOpLHS, new object[] { childExpr.Operator.ToString() }));
                exception.Data["ErrorObject"] = childExpr;
                throw exception;
            }
            if (childExpr.Right == null)
            {
                RuleEvaluationException exception2 = new RuleEvaluationException(string.Format(CultureInfo.CurrentCulture, Messages.NullBinaryOpRHS, new object[] { childExpr.Operator.ToString() }));
                exception2.Data["ErrorObject"] = childExpr;
                throw exception2;
            }
            switch (childExpr.Operator)
            {
            case CodeBinaryOperatorType.Add:
                str3 = " + ";
                break;

            case CodeBinaryOperatorType.Subtract:
                str3 = " - ";
                break;

            case CodeBinaryOperatorType.Multiply:
                str3 = " * ";
                break;

            case CodeBinaryOperatorType.Divide:
                str3 = " / ";
                break;

            case CodeBinaryOperatorType.Modulus:
                str3 = " % ";
                break;

            case CodeBinaryOperatorType.IdentityInequality:
                str3 = " != ";
                break;

            case CodeBinaryOperatorType.IdentityEquality:
            case CodeBinaryOperatorType.ValueEquality:
                str3 = " == ";
                break;

            case CodeBinaryOperatorType.BitwiseOr:
                str3 = " | ";
                break;

            case CodeBinaryOperatorType.BitwiseAnd:
                str3 = " & ";
                break;

            case CodeBinaryOperatorType.BooleanOr:
                str3 = " || ";
                break;

            case CodeBinaryOperatorType.BooleanAnd:
                str3 = " && ";
                break;

            case CodeBinaryOperatorType.LessThan:
                str3 = " < ";
                break;

            case CodeBinaryOperatorType.LessThanOrEqual:
                str3 = " <= ";
                break;

            case CodeBinaryOperatorType.GreaterThan:
                str3 = " > ";
                break;

            case CodeBinaryOperatorType.GreaterThanOrEqual:
                str3 = " >= ";
                break;

            default:
            {
                NotSupportedException exception3 = new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Messages.BinaryOpNotSupported, new object[] { childExpr.Operator.ToString() }));
                exception3.Data["ErrorObject"] = childExpr;
                throw exception3;
            }
            }
            CodeExpression left  = childExpr.Left;
            CodeExpression right = childExpr.Right;

            if (childExpr.Operator == CodeBinaryOperatorType.ValueEquality)
            {
                CodePrimitiveExpression expression5 = right as CodePrimitiveExpression;
                if (expression5 != null)
                {
                    object obj2 = expression5.Value;
                    if (((obj2 != null) && (obj2.GetType() == typeof(bool))) && !((bool)obj2))
                    {
                        CodeBinaryOperatorExpression expression6 = left as CodeBinaryOperatorExpression;
                        if ((expression6 == null) || (expression6.Operator != CodeBinaryOperatorType.ValueEquality))
                        {
                            flag = RuleDecompiler.MustParenthesize(left, parentExpression);
                            if (flag)
                            {
                                stringBuilder.Append("(");
                            }
                            stringBuilder.Append("!");
                            RuleExpressionWalker.Decompile(stringBuilder, left, new CodeCastExpression());
                            if (flag)
                            {
                                stringBuilder.Append(")");
                            }
                            return;
                        }
                        str3  = " != ";
                        left  = expression6.Left;
                        right = expression6.Right;
                    }
                }
            }
            else if (childExpr.Operator == CodeBinaryOperatorType.Subtract)
            {
                CodePrimitiveExpression expression7 = left as CodePrimitiveExpression;
                if ((expression7 != null) && (expression7.Value != null))
                {
                    object   obj3     = expression7.Value;
                    TypeCode typeCode = Type.GetTypeCode(obj3.GetType());
                    bool     flag2    = false;
                    switch (typeCode)
                    {
                    case TypeCode.Int32:
                        flag2 = ((int)obj3) == 0;
                        break;

                    case TypeCode.Int64:
                        flag2 = ((long)obj3) == 0L;
                        break;

                    case TypeCode.Single:
                        flag2 = ((float)obj3) == 0f;
                        break;

                    case TypeCode.Double:
                        flag2 = ((double)obj3) == 0.0;
                        break;

                    case TypeCode.Decimal:
                        flag2 = ((decimal)obj3) == 0M;
                        break;
                    }
                    if (flag2)
                    {
                        flag = RuleDecompiler.MustParenthesize(right, parentExpression);
                        if (flag)
                        {
                            stringBuilder.Append("(");
                        }
                        stringBuilder.Append("-");
                        RuleExpressionWalker.Decompile(stringBuilder, right, new CodeCastExpression());
                        if (flag)
                        {
                            stringBuilder.Append(")");
                        }
                        return;
                    }
                }
            }
            flag = RuleDecompiler.MustParenthesize(childExpr, parentExpression);
            if (flag)
            {
                stringBuilder.Append("(");
            }
            RuleExpressionWalker.Decompile(stringBuilder, left, childExpr);
            stringBuilder.Append(str3);
            RuleExpressionWalker.Decompile(stringBuilder, right, childExpr);
            if (flag)
            {
                stringBuilder.Append(")");
            }
        }