Ejemplo n.º 1
0
        /// <summary>
        ///     Adds aliases to <see cref="OptionBuilder{T}.Aliases"/>.
        /// </summary>
        /// <typeparam name="T">Type of the option.</typeparam>
        /// <param name="builder">Source builder.</param>
        /// <param name="aliases">Aliases to add to the option.</param>
        /// <returns><paramref name="builder"/>, to allow chaining.</returns>
        /// <exception cref="ArgumentException"><paramref name="aliases"/> contains an invalid alias.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception>
        public static OptionBuilder <T> AddAliases <T>(this OptionBuilder <T> builder, IEnumerable <string> aliases)
        {
            if (builder is null)
            {
                throw Exceptions.BuildArgumentNull(nameof(builder));
            }

            foreach (var alias in aliases ?? Enumerable.Empty <string>())
            {
                try
                {
                    builder.Aliases.Add(alias);
                }
                catch (ArgumentException exArg)
                {
                    throw Exceptions.BuildArgumentContainsInvalidAlias(nameof(aliases), exArg);
                }
            }

            return(builder);
        }
Ejemplo n.º 2
0
        internal AliasCollection(params string[] aliases)
        {
            if (aliases is null)
            {
                throw Exceptions.BuildArgumentNull(nameof(aliases));
            }
            else if (aliases.Length == 0)
            {
                throw Exceptions.BuildArgumentEmptyAliases(nameof(aliases));
            }

            for (var i = 0; i < aliases.Length; i += 1)
            {
                try
                {
                    this.Add(aliases[i]);
                }
                catch (ArgumentException exArg)
                {
                    throw Exceptions.BuildArgumentContainsInvalidAlias(nameof(aliases), exArg);
                }
            }
        }