Beispiel #1
0
 private bool EvaluateConditionalDirectiveExpression(Microsoft.StyleCop.SourceCode sourceCode, Expression expression, Configuration configuration)
 {
     bool flag2;
     bool flag3;
     switch (expression.ExpressionType)
     {
         case ExpressionType.Parenthesized:
         {
             ParenthesizedExpression expression6 = expression as ParenthesizedExpression;
             return this.EvaluateConditionalDirectiveExpression(sourceCode, expression6.InnerExpression, configuration);
         }
         case ExpressionType.Relational:
         {
             RelationalExpression expression4 = expression as RelationalExpression;
             flag2 = this.EvaluateConditionalDirectiveExpression(sourceCode, expression4.LeftHandSide, configuration);
             flag3 = this.EvaluateConditionalDirectiveExpression(sourceCode, expression4.RightHandSide, configuration);
             if (expression4.OperatorType != RelationalExpression.Operator.EqualTo)
             {
                 if (expression4.OperatorType != RelationalExpression.Operator.NotEqualTo)
                 {
                     throw new SyntaxException(sourceCode, expression.Tokens.First.Value.LineNumber);
                 }
                 return (flag2 != flag3);
             }
             return (flag2 == flag3);
         }
         case ExpressionType.Unary:
         {
             UnaryExpression expression5 = expression as UnaryExpression;
             if (expression5.OperatorType != UnaryExpression.Operator.Not)
             {
                 throw new SyntaxException(sourceCode, expression.Tokens.First.Value.LineNumber);
             }
             return !this.EvaluateConditionalDirectiveExpression(sourceCode, expression5.Value, configuration);
         }
         case ExpressionType.ConditionalLogical:
         {
             ConditionalLogicalExpression expression3 = expression as ConditionalLogicalExpression;
             flag2 = this.EvaluateConditionalDirectiveExpression(sourceCode, expression3.LeftHandSide, configuration);
             flag3 = this.EvaluateConditionalDirectiveExpression(sourceCode, expression3.RightHandSide, configuration);
             if (expression3.OperatorType == ConditionalLogicalExpression.Operator.And)
             {
                 return (flag2 && flag3);
             }
             return (flag2 || flag3);
         }
         case ExpressionType.Literal:
         {
             LiteralExpression expression2 = expression as LiteralExpression;
             if (expression2.Text == "false")
             {
                 return false;
             }
             if (expression2.Text == "true")
             {
                 return true;
             }
             if ((this.undefines != null) && this.undefines.ContainsKey(expression2.Text))
             {
                 return false;
             }
             return (((this.defines != null) && this.defines.ContainsKey(expression2.Text)) || ((configuration != null) && configuration.Contains(expression2.Text)));
         }
     }
     throw new SyntaxException(sourceCode, expression.Tokens.First.Value.LineNumber);
 }
        /// <summary>
        /// Compares the given configuration with the given list of flags.
        /// </summary>
        /// <param name="configuration">The configuration object.</param>
        /// <param name="flagList">The list of flags.</param>
        /// <returns>Returns true if the configuration is identical to the flag list, or
        /// false otherwise.</returns>
        private static bool CompareCachedConfiguration(Configuration configuration, string flagList)
        {
            Param.AssertNotNull(configuration, "configuration");
            Param.AssertNotNull(flagList, "flagList");

            // Split the flags.
            string[] flags = new string[0];
            string trimmedList = flagList.Trim();
            if (trimmedList.Length > 0)
            {
                flags = flagList.Split(';');
            }

            // If the counts are different, the configurations are different.
            if (flags.Length != configuration.Flags.Count)
            {
                return false;
            }

            // Make sure each of the flags exists in the configuration.
            foreach (string flag in flags)
            {
                if (!configuration.Contains(flag))
                {
                    return false;
                }
            }

            return true;
        }
 private static bool CompareCachedConfiguration(Configuration configuration, string flagList)
 {
     string[] strArray = new string[0];
     if (flagList.Trim().Length > 0)
     {
         strArray = flagList.Split(new char[] { ';' });
     }
     if (strArray.Length != configuration.Flags.Count)
     {
         return false;
     }
     foreach (string str2 in strArray)
     {
         if (!configuration.Contains(str2))
         {
             return false;
         }
     }
     return true;
 }