using System; using System.Collections.Generic; namespace LibAC.Arguments { /// /// Represents a collection of arguments. /// public class Arguments { /// /// The dictionary containing argument names and their corresponding instances. /// private readonly Dictionary _arguments; /// /// Returns the total number of stored arguments /// public int Count => _arguments.Count; /// /// Initializes a new instance of the class. /// public Arguments() { _arguments = new Dictionary(StringComparer.OrdinalIgnoreCase); } /// /// Adds an argument to the collection. /// /// The argument to add. /// Thrown if an argument with the same key already exists. internal void AddArgument(IArgument argument) { if (_arguments.ContainsKey(argument.Key)) throw new ArgumentException($"An argument with the key '{argument.Key}' already exists."); _arguments[argument.Key] = argument; } /// /// Retrieves an argument by its key. /// /// The key of the argument to retrieve. /// The associated with the key. /// Thrown if the key is not found in the collection. public IArgument GetArgument(string key) { if (!_arguments.TryGetValue(key, out var argument)) throw new KeyNotFoundException($"No argument found with the key '{key}'."); return argument; } /// /// Checks if an argument with the specified key exists in the collection. /// /// The key to check for. /// true if an argument with the key exists; otherwise, false. public bool HasArg(string key) { return _arguments.ContainsKey(key); // Dictionary method remains unchanged } /// /// Removes an argument from the collection by its key. /// /// The key of the argument to remove. /// true if the argument was removed; otherwise, false. public bool RemoveArgument(string key) { return _arguments.Remove(key); } /// /// Gets all arguments in the collection. /// /// An enumerable of all instances in the collection. public IEnumerable GetAllArguments() { return _arguments.Values; } /// /// Clears all arguments from the collection. /// public void Clear() { _arguments.Clear(); } } public class ArgumentBuilder { private readonly Arguments _arguments; public ArgumentBuilder() { _arguments = new Arguments(); } /// /// Adds a predefined argument for a string type. /// public ArgumentBuilder withStringArgument(string key, string? value = null, bool required = false) { IArgument arg = new StringArgument(key, value); arg.required = required; _arguments.AddArgument(arg); return this; } /// /// Adds a predefined argument for an integer type. /// public ArgumentBuilder withIntegerArgument(string key, int? value = null, bool required = false) { IArgument arg = new IntegerArgument(key, value); arg.required = required; _arguments.AddArgument(arg); return this; } /// /// Adds a predefined argument for a boolean type. /// public ArgumentBuilder withBooleanArgument(string key, bool? value = null, bool required = false) { IArgument arg = new BooleanArgument(key, value); arg.required = required; _arguments.AddArgument(arg); return this; } /// /// Adds a predefined argument for a float type. /// public ArgumentBuilder withFloatArgument(string key, float? value = null, bool required = false) { IArgument arg = new FloatArgument(key, value); arg.required = required; _arguments.AddArgument(arg); return this; } /// /// Adds a predefined argument for a double type. /// public ArgumentBuilder withDoubleArgument(string key, double? value = null, bool required = false) { IArgument arg = new DoubleArgument(key, value); arg.required = required; _arguments.AddArgument(arg); return this; } /// /// Adds a predefined 'help' argument (usually a flag). /// public ArgumentBuilder withHelpArgument() { _arguments.AddArgument(new BooleanArgument("help", false)); // or true based on logic return this; } /// /// Adds a predefined 'version' argument. /// public ArgumentBuilder withVersionArgument() { _arguments.AddArgument(new BooleanArgument("version")); return this; } /// /// Returns the constructed Arguments object containing all the added arguments. /// public Arguments Build() { return _arguments; } } }