コード例 #1
0
        private bool IsInNeedOfFixing(IEqualityExpression binexpr)
        {
            if (binexpr.EqualityType != EqualityExpressionType.EQEQ)
            {
                return(false);
            }

            // Is the right hand side a string literal?
            var right = binexpr.RightOperand as ILiteralExpression;

            if (right == null || !right.ToTreeNode().GetTokenType().IsStringLiteral)
            {
                return(false);
            }


            // Is the left hand side a call to Enum.ToString followed by a zero or more ToUpper,ToLower & Trim calls?
            var left = binexpr.LeftOperand as IInvocationExpression;

            if (left == null)
            {
                return(false);
            }

            var visitor = new MyIsExpressionStringCallsOnAnEnum();

            left.Accept(visitor);

            if (visitor.Found)
            {
                var enumSymbolTable = visitor.FoundEnumReference.GetReferenceSymbolTable(true).Filter(new MyFilter());

                foreach (ISymbolInfo info in enumSymbolTable.AllSymbolInfos())
                {
                    if (string.Compare(info.ShortName, right.ConstantValue.Value.ToString(), true) == 0)
                    {
                        ReplacementText = visitor.EnumReferenceName + " == " + visitor.EnumDeclaredName + "." + info.ShortName;
                        return(true);
                    }
                    // TODO: Technically, a case mismatch should result in a "conditional is always false" error.
                }
            }
            return(false);
        }
        private bool IsInNeedOfFixing(IEqualityExpression binexpr)
        {
            if(binexpr.EqualityType != EqualityExpressionType.EQEQ) return false;

            // Is the right hand side a string literal?
            var right = binexpr.RightOperand as ILiteralExpression;
            if (right == null || !right.ToTreeNode().GetTokenType().IsStringLiteral)
            {
                return false;
            }

            // Is the left hand side a call to Enum.ToString followed by a zero or more ToUpper,ToLower & Trim calls?
            var left = binexpr.LeftOperand as IInvocationExpression;
            if(left == null)
            {
                return false;
            }

            var visitor = new MyIsExpressionStringCallsOnAnEnum();
            left.Accept( visitor );

            if (visitor.Found)
            {
                var enumSymbolTable = visitor.FoundEnumReference.GetReferenceSymbolTable(true).Filter(new MyFilter());

                foreach (ISymbolInfo info in enumSymbolTable.AllSymbolInfos())
                {
                    if (string.Compare(info.ShortName, right.ConstantValue.Value.ToString(), true) == 0)
                    {
                        ReplacementText = visitor.EnumReferenceName + " == " + visitor.EnumDeclaredName + "." + info.ShortName;
                        return true;
                    }
                    // TODO: Technically, a case mismatch should result in a "conditional is always false" error.
                }
            }
            return false;
        }