コード例 #1
0
            /// <summary>
            ///     Create token that matches provided string, string needs to be a single value
            /// </summary>
            /// <param name="tokenString"></param>
            /// <returns></returns>
            /// <exception cref="Exception"></exception>
            public static Token GetMatchingToken(string tokenString)
            {
                if (Equal.TryParse(tokenString, out var token))
                {
                    return(token);
                }
                if (LessThen.TryParse(tokenString, out token))
                {
                    return(token);
                }
                if (LessThenEqual.TryParse(tokenString, out token))
                {
                    return(token);
                }
                if (GreaterThen.TryParse(tokenString, out token))
                {
                    return(token);
                }
                if (GreaterThenEqual.TryParse(tokenString, out token))
                {
                    return(token);
                }
                if (Between.TryParse(tokenString, out token))
                {
                    return(token);
                }

                throw new Exception($"Provided string was invalid {tokenString}, please provide valid range token");
            }
コード例 #2
0
 public static bool TryParse(string tokenString, out Token token)
 {
     if (tokenString[0] == '<' && tokenString[1] == '=' &&
         int.TryParse(tokenString.Remove(0, 2), out var result))
     {
         token = new LessThenEqual()
         {
             _value = result
         };
         return(true);
     }
     token = null;
     return(false);
 }