Beispiel #1
0
        /// <summary>
        ///     Adds a suggestion source from a collection to <see cref="OptionBuilder{T}.Suggestions"/>.
        /// </summary>
        /// <typeparam name="T">Type of the option.</typeparam>
        /// <param name="builder">Source builder.</param>
        /// <param name="suggestions">Collection of suggestions.</param>
        /// <returns><paramref name="builder"/>, to allow chaining.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception>
        public static OptionBuilder <T> AddSuggestions <T>(this OptionBuilder <T> builder, IEnumerable <string> suggestions)
        {
            if (builder is null)
            {
                throw Exceptions.BuildArgumentNull(nameof(builder));
            }

            var suggestionsCopy = suggestions?.ToArray() ?? Array.Empty <string>();

            return(builder.AddSuggestions(GetSuggestionsFromCollection));

            IEnumerable <string> GetSuggestionsFromCollection(ParseResult?parseResult, string?textToMatch)
            {
                return(suggestionsCopy);
            }
        }
Beispiel #2
0
 /// <summary>
 ///     Adds a suggestion source built from the parameters to <see cref="OptionBuilder{T}.Suggestions"/>.
 /// </summary>
 /// <typeparam name="T">Type of the option.</typeparam>
 /// <param name="builder">Source builder.</param>
 /// <param name="suggestions">Array of suggestions.</param>
 /// <returns><paramref name="builder"/>, to allow chaining.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception>
 public static OptionBuilder <T> AddSuggestions <T>(this OptionBuilder <T> builder, params string[] suggestions)
 {
     return(builder.AddSuggestions((IEnumerable <string>)suggestions));
 }