/// <summary> /// Sets the <see cref="CommandBuilder.Name"/> in the command builder. /// </summary> /// <param name="builder">Source builder.</param> /// <param name="name">Name of the command. It cannot be <see langword="null"/>, empty or contain whitespace after removing the prefix. Root commands can have null names.</param> /// <returns><paramref name="builder"/>, to allow chaining.</returns> /// <exception cref="ArgumentException">The name of the command is <see langword="null"/>, empty or contains whitespace after removing the prefix.</exception> /// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception> public static CommandBuilder SetName(this CommandBuilder builder, string name) { (builder ?? throw Exceptions.BuildArgumentNull(nameof(builder))) .Name = (builder.IsRoot && name is null) || Validations.IsValidCommandName(name) ? name : throw Exceptions.BuildArgumentInvalidCommandName(nameof(name)); return(builder); }
/// <summary> /// Sets the <see cref="ArgumentBuilder{T}.Name"/> in the argument builder. /// </summary> /// <typeparam name="T">Type of the argument.</typeparam> /// <param name="builder">Source builder.</param> /// <param name="name">Name of the argument. It cannot be <see langword="null"/> or whitespace-only.</param> /// <returns><paramref name="builder"/>, to allow chaining.</returns> /// <exception cref="ArgumentException">The name of the argument is <see langword="null"/> or composed of only whitespaces.</exception> /// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception> public static ArgumentBuilder <T> SetName <T>(this ArgumentBuilder <T> builder, string name) { (builder ?? throw Exceptions.BuildArgumentNull(nameof(builder))) .Name = Validations.IsValidArgumentName(name) ? name : throw Exceptions.BuildArgumentInvalidArgumentName(nameof(name)); return(builder); }
/// <summary> /// Initializes a new instance of the <see cref="ArgumentBuilder{T}"/> class. /// </summary> /// <param name="name">Name of the argument. It cannot be <see langword="null"/> or whitespace-only.</param> /// <exception cref="ArgumentException"><paramref name="name"/> is <see langword="null"/> or composed of only whitespaces.</exception> public ArgumentBuilder(string name) { this.name = Validations.IsValidArgumentName(name) ? name : throw Exceptions.BuildArgumentInvalidArgumentName(nameof(name)); }
/// <inheritdoc/> /// <exception cref="ArgumentException"><paramref name="item"/> is an invalid alias.</exception> protected override void SetItem(int index, string item) { base.SetItem(index, Validations.IsValidAlias(item) ? item : throw Exceptions.BuildArgumentInvalidAlias(nameof(item))); }