Esempio n. 1
0
        /// <summary>
        /// Adds an alias to this command.
        /// </summary>
        /// <param name="alias">Alias to add to the command.</param>
        /// <returns>This builder.</returns>
        public CommandBuilder WithAlias(string alias)
        {
            if (alias.ToCharArray().Any(xc => char.IsWhiteSpace(xc)))
            {
                throw new ArgumentException("Aliases cannot contain whitespace characters or null strings.", nameof(alias));
            }

            if (Name == alias || AliasList.Contains(alias))
            {
                throw new ArgumentException("Aliases cannot contain the command name, and cannot be duplicate.", nameof(alias));
            }

            AliasList.Add(alias);
            return(this);
        }
Esempio n. 2
0
        /// <summary>
        /// Sets the name for this command.
        /// </summary>
        /// <param name="name">Name for this command.</param>
        /// <returns>This builder.</returns>
        public CommandBuilder WithName(string name)
        {
            if (name == null || name.ToCharArray().Any(xc => char.IsWhiteSpace(xc)))
            {
                throw new ArgumentException("Command name cannot be null or contain any whitespace characters.", nameof(name));
            }

            if (Name != null)
            {
                throw new InvalidOperationException("This command already has a name.");
            }

            if (AliasList.Contains(name))
            {
                throw new ArgumentException("Command name cannot be one of its aliases.", nameof(name));
            }

            Name = name;
            return(this);
        }