Пример #1
0
 /// <summary>
 /// Matches the currently <see cref="ActiveToken" /> to any of the provided <see cref="TokenType" />. The active
 /// token must match one of the provided types for the match to succeed.
 /// </summary>
 /// <param name="primaryTokenType">Type of the primary token to check for.</param>
 /// <param name="additionalTypes">Any additional tokens to check for.</param>
 /// <returns><c>true</c> if a match is found, <c>false</c> otherwise.</returns>
 public bool Match(TokenType primaryTokenType, params TokenType[] additionalTypes)
 {
     if (additionalTypes == null || additionalTypes.Length == 0)
     {
         return(this.Match(primaryTokenType));
     }
     else
     {
         return(primaryTokenType.AsEnumerable().Concat(additionalTypes).Any(this.Match));
     }
 }
Пример #2
0
 /// <summary>
 /// Matches the currently <see cref="ActiveToken" /> to any of the provided <see cref="TokenType" />.
 /// The active token must match one of the provided values or an exception is thrown.
 /// </summary>
 /// <param name="primaryTokenType">Type of the primary token to check for.</param>
 /// <param name="additionalTypes">Any additional tokens to check for.</param>
 public void MatchOrThrow(TokenType primaryTokenType, params TokenType[] additionalTypes)
 {
     if (additionalTypes == null || additionalTypes.Length == 0)
     {
         this.MatchOrThrow(primaryTokenType);
     }
     else
     {
         var typeCollection = primaryTokenType.AsEnumerable().Concat(additionalTypes);
         var tokensMatched  = typeCollection.Where(this.Match);
         if (!tokensMatched.Any())
         {
             var errors = "[" + string.Join(", ", typeCollection.Select(TokenTypeTextForErrorMessage).Select(x => x.ToString())) + "]";
             GraphQLSyntaxException.ThrowFromExpectation(
                 this.Location,
                 errors,
                 this.ActiveTokenTypeDescrption.ToString());
         }
     }
 }