using System.Collections.ObjectModel;
namespace VpSharp.Commands.Attributes;
///
/// Defines the aliases of a command.
///
[AttributeUsage(AttributeTargets.Method)]
[CLSCompliant(false)]
public sealed class AliasesAttribute : Attribute
{
///
/// Initializes a new instance of the class.
///
/// The first alias.
/// Additional aliases.
///
/// is .
/// -or-
/// is .
///
///
/// is empty, or consists of only whitespace.
/// -or-
/// An element in is null, empty, or consists of only whitespace.
///
#pragma warning disable CA1019
public AliasesAttribute(string alias, params string[] aliases)
#pragma warning restore CA1019
{
if (alias is null)
{
throw new ArgumentNullException(nameof(alias));
}
if (aliases is null)
{
throw new ArgumentNullException(nameof(aliases));
}
if (string.IsNullOrWhiteSpace(alias))
{
throw new ArgumentException("Alias cannot be empty");
}
foreach (string a in aliases)
{
if (string.IsNullOrWhiteSpace(a))
{
throw new ArgumentException("Cannot have a null alias");
}
}
var buffer = new string[aliases.Length + 1];
buffer[0] = alias;
Array.Copy(aliases, 0, buffer, 1, aliases.Length);
Aliases = new ReadOnlyCollection(buffer);
}
///
/// Gets the command aliases.
///
/// The command aliases.
public IReadOnlyList Aliases { get; }
}