예제 #1
0
        private bool CheckIfStatementStructure(IfStatement theIf)
        {
            if (theIf.Else == null && theIf.Condition.CodeNodeType == CodeNodeType.BinaryExpression)
            {
                if (theIf.Then.Statements.Count == 1 && theIf.Then.Statements[0].CodeNodeType == CodeNodeType.ExpressionStatement)
                {
                    this.cachingVersion = DelegateCachingVersion.V1;
                    return(true);
                }
                else if (theIf.Then.Statements.Count == 3)
                {
                    ExpressionStatement first = theIf.Then.Statements[0] as ExpressionStatement;
                    if (first == null)
                    {
                        return(false);
                    }

                    BinaryExpression firstBinary = first.Expression as BinaryExpression;
                    if (firstBinary == null)
                    {
                        return(false);
                    }

                    if (!firstBinary.IsAssignmentExpression ||
                        firstBinary.Left.CodeNodeType != CodeNodeType.VariableReferenceExpression ||
                        firstBinary.Right.CodeNodeType != CodeNodeType.VariableReferenceExpression ||
                        !initializationsToRemove.ContainsKey((firstBinary.Right as VariableReferenceExpression).Variable))
                    {
                        return(false);
                    }

                    if (theIf.Then.Statements[1].CodeNodeType != CodeNodeType.ExpressionStatement)
                    {
                        return(false);
                    }

                    ExpressionStatement third = theIf.Then.Statements[2] as ExpressionStatement;
                    if (third == null)
                    {
                        return(false);
                    }

                    BinaryExpression thirdBinary = third.Expression as BinaryExpression;
                    if (thirdBinary == null)
                    {
                        return(false);
                    }

                    if (!thirdBinary.IsAssignmentExpression ||
                        thirdBinary.Left.CodeNodeType != CodeNodeType.FieldReferenceExpression ||
                        thirdBinary.Right.CodeNodeType != CodeNodeType.VariableReferenceExpression ||
                        !initializationsToRemove.ContainsKey((thirdBinary.Right as VariableReferenceExpression).Variable))
                    {
                        return(false);
                    }

                    this.cachingVersion = DelegateCachingVersion.V2;
                    return(true);
                }
            }

            return(false);
        }
        private bool CheckIfStatementStructure(IfStatement theIf)
        {
            if (theIf.Else == null && theIf.Condition.CodeNodeType == CodeNodeType.BinaryExpression)
            {
                if (theIf.Then.Statements.Count == 1 && theIf.Then.Statements[0].CodeNodeType == CodeNodeType.ExpressionStatement)
                {
                    this.cachingVersion = DelegateCachingVersion.V1;
                    return true;
                }
                else if (theIf.Then.Statements.Count == 3)
                {
                    ExpressionStatement first = theIf.Then.Statements[0] as ExpressionStatement;
                    if (first == null)
                    {
                        return false;
                    }

                    BinaryExpression firstBinary = first.Expression as BinaryExpression;
                    if (firstBinary == null)
                    {
                        return false;
                    }

                    if (!firstBinary.IsAssignmentExpression ||
                        firstBinary.Left.CodeNodeType != CodeNodeType.VariableReferenceExpression ||
                        firstBinary.Right.CodeNodeType != CodeNodeType.VariableReferenceExpression ||
                        !initializationsToRemove.ContainsKey((firstBinary.Right as VariableReferenceExpression).Variable))
                    {
                        return false;
                    }

                    if (theIf.Then.Statements[1].CodeNodeType != CodeNodeType.ExpressionStatement)
                    {
                        return false;
                    }

                    ExpressionStatement third = theIf.Then.Statements[2] as ExpressionStatement;
                    if (third == null)
                    {
                        return false;
                    }

                    BinaryExpression thirdBinary = third.Expression as BinaryExpression;
                    if (thirdBinary == null)
                    {
                        return false;
                    }

                    if (!thirdBinary.IsAssignmentExpression ||
                        thirdBinary.Left.CodeNodeType != CodeNodeType.FieldReferenceExpression ||
                        thirdBinary.Right.CodeNodeType != CodeNodeType.VariableReferenceExpression ||
                        !initializationsToRemove.ContainsKey((thirdBinary.Right as VariableReferenceExpression).Variable))
                    {
                        return false;
                    }

                    this.cachingVersion = DelegateCachingVersion.V2;
                    return true;
                }
            }

            return false;
        }