1
0
mirror of https://github.com/oliverbooth/VpSharp synced 2024-11-22 18:58:48 +00:00

Don't return arrays in public properties

This commit is contained in:
Oliver Booth 2022-11-29 19:06:15 +00:00
parent 66fe507b8d
commit 20481a1bdd
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
3 changed files with 16 additions and 11 deletions

View File

@ -1,4 +1,6 @@
namespace VpSharp.Commands.Attributes;
using System.Collections.ObjectModel;
namespace VpSharp.Commands.Attributes;
/// <summary>
/// Defines the aliases of a command.
@ -39,14 +41,15 @@ public sealed class AliasesAttribute : Attribute
}
}
Aliases = new string[aliases.Length + 1];
Aliases[0] = alias;
Array.Copy(aliases, 0, Aliases, 1, aliases.Length);
var buffer = new string[aliases.Length + 1];
buffer[0] = alias;
Array.Copy(aliases, 0, buffer, 1, aliases.Length);
Aliases = new ReadOnlyCollection<string>(buffer);
}
/// <summary>
/// Gets the command aliases.
/// </summary>
/// <value>The command aliases.</value>
public string[] Aliases { get; }
public IReadOnlyList<string> Aliases { get; }
}

View File

@ -1,4 +1,5 @@
using System.Reflection;
using System.Collections.ObjectModel;
using System.Reflection;
namespace VpSharp.Commands;
@ -10,7 +11,7 @@ public sealed class Command
internal Command(string name, string[] aliases, MethodInfo method, CommandModule module)
{
Name = name;
Aliases = aliases[..];
Aliases = new ReadOnlyCollection<string>(aliases);
Method = method;
Module = module;
Parameters = method.GetParameters()[1..];
@ -20,7 +21,7 @@ public sealed class Command
/// Gets the aliases for this command.
/// </summary>
/// <value>The aliases.</value>
public string[] Aliases { get; }
public IReadOnlyList<string> Aliases { get; }
/// <summary>
/// Gets the name of this command.

View File

@ -1,4 +1,5 @@
using System.Drawing;
using System.Collections.ObjectModel;
using System.Drawing;
using VpSharp.Entities;
namespace VpSharp.Commands;
@ -18,7 +19,7 @@ public sealed class CommandContext
CommandName = commandName;
Alias = alias;
RawArguments = rawArguments;
Arguments = rawArguments.Split();
Arguments = new ReadOnlyCollection<string>(rawArguments.Split());
}
/// <summary>
@ -31,7 +32,7 @@ public sealed class CommandContext
/// Gets the arguments of the command.
/// </summary>
/// <value>The arguments passed by the avatar.</value>
public string[] Arguments { get; }
public IReadOnlyList<string> Arguments { get; }
/// <summary>
/// Gets the avatar who executed the command.