Пример #1
0
        /// <summary>
        /// Determines whether the format string is valid.
        /// </summary>
        /// <param name="token">The token to evaluate.</param>
        /// <returns>
        /// <c>true</c> if the specified format contains the text; otherwise, <c>false</c>.
        /// </returns>
        internal static bool EvaluateFormat(string token)
        {
            if ((token == null) || (token == string.Empty))
            {
                return(false);
            }
            string str = DefaultTokens.TrimSquareBracket(token);

            return(((str != null) && !(str == string.Empty)) && DefaultTokens.IsOperator(str[0]));
        }
Пример #2
0
        /// <summary>
        /// Creates a new condition format with the specified string expression.
        /// </summary>
        /// <param name="token">The string expression for this format.</param>
        /// <remarks>Examples of conditional string expressions are "[&gt;10]" and "[&gt;=0]".</remarks>
        public ConditionFormatPart(string token) : base(token)
        {
            string str = DefaultTokens.TrimSquareBracket(token);

            if (string.IsNullOrEmpty(str))
            {
                throw new ArgumentException(ResourceStrings.FormatterIllegaTokenError);
            }
            StringBuilder builder = null;
            int           num     = 0;

            while (num < str.Length)
            {
                char c = str[num];
                if (!DefaultTokens.IsOperator(c))
                {
                    break;
                }
                if (builder == null)
                {
                    builder = new StringBuilder();
                }
                builder.Append(c);
                num++;
            }
            if (builder == null)
            {
                throw new ArgumentException(ResourceStrings.FormatterIllegaTokenError);
            }
            string str2 = builder.ToString();

            builder = null;
            switch (str2)
            {
            case "<":
                this.compareOperator = GeneralCompareType.LessThan;
                break;

            case "<=":
                this.compareOperator = GeneralCompareType.LessThanOrEqualsTo;
                break;

            case "=":
                this.compareOperator = GeneralCompareType.EqualsTo;
                break;

            case ">=":
                this.compareOperator = GeneralCompareType.GreaterThanOrEqualsTo;
                break;

            case ">":
                this.compareOperator = GeneralCompareType.GreaterThan;
                break;

            case "<>":
                this.compareOperator = GeneralCompareType.NotEqualsTo;
                break;

            default:
                throw new ArgumentException(ResourceStrings.FormatterIllegaTokenError);
            }
            while (num < str.Length)
            {
                char ch2 = str[num];
                if (DefaultTokens.IsOperator(ch2))
                {
                    throw new ArgumentException(ResourceStrings.FormatterIllegaTokenError);
                }
                if (builder == null)
                {
                    builder = new StringBuilder();
                }
                builder.Append(ch2);
                num++;
            }
            if (builder == null)
            {
                throw new ArgumentException(ResourceStrings.FormatterIllegaTokenError);
            }
            if (!double.TryParse(builder.ToString(), out this.value))
            {
                throw new ArgumentException(ResourceStrings.FormatterIllegaTokenError);
            }
        }