Ejemplo n.º 1
0
        /// <summary>
        ///     Adds a suggestion source from a collection to <see cref="ArgumentBuilder{T}.Suggestions"/>.
        /// </summary>
        /// <typeparam name="T">Type of the argument.</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 ArgumentBuilder <T> AddSuggestions <T>(this ArgumentBuilder <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);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 ///     Adds a suggestion source built from the parameters to <see cref="ArgumentBuilder{T}.Suggestions"/>.
 /// </summary>
 /// <typeparam name="T">Type of the argument.</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 ArgumentBuilder <T> AddSuggestions <T>(this ArgumentBuilder <T> builder, params string[] suggestions)
 {
     return(builder.AddSuggestions((IEnumerable <string>)suggestions));
 }