refactor: replace throw helper with explicit null check

This commit is contained in:
Oliver Booth 2024-02-15 22:38:48 +00:00
parent 682edbe8c6
commit 5ffc7a5a3b
Signed by: oliverbooth
GPG Key ID: E60B570D1B7557B5
18 changed files with 206 additions and 48 deletions

View File

@ -28,8 +28,15 @@ public sealed class AliasesAttribute : Attribute
public AliasesAttribute(string alias, params string[] aliases) public AliasesAttribute(string alias, params string[] aliases)
#pragma warning restore CA1019 #pragma warning restore CA1019
{ {
ArgumentNullException.ThrowIfNull(alias); if (alias is null)
ArgumentNullException.ThrowIfNull(aliases); {
throw new ArgumentNullException(nameof(alias));
}
if (aliases is null)
{
throw new ArgumentNullException(nameof(aliases));
}
if (string.IsNullOrWhiteSpace(alias)) if (string.IsNullOrWhiteSpace(alias))
{ {

View File

@ -14,7 +14,11 @@ public sealed class CommandAttribute : Attribute
/// <exception cref="ArgumentException"><paramref name="name" /> is empty, or consists of only whitespace.</exception> /// <exception cref="ArgumentException"><paramref name="name" /> is empty, or consists of only whitespace.</exception>
public CommandAttribute(string name) public CommandAttribute(string name)
{ {
ArgumentNullException.ThrowIfNull(name); if (name is null)
{
throw new ArgumentNullException(nameof(name));
}
if (string.IsNullOrWhiteSpace(name)) if (string.IsNullOrWhiteSpace(name))
{ {
throw new ArgumentException("Name cannot be empty"); throw new ArgumentException("Name cannot be empty");

View File

@ -14,7 +14,11 @@ public sealed class RequireAvatarNameAttribute : PreExecutionCheckAttribute
/// <exception cref="ArgumentNullException"><paramref name="names" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="names" /> is <see langword="null" />.</exception>
public RequireAvatarNameAttribute(IEnumerable<string> names) public RequireAvatarNameAttribute(IEnumerable<string> names)
{ {
ArgumentNullException.ThrowIfNull(names); if (names is null)
{
throw new ArgumentNullException(nameof(names));
}
Names = names.ToArray(); Names = names.ToArray();
} }
@ -26,7 +30,11 @@ public sealed class RequireAvatarNameAttribute : PreExecutionCheckAttribute
[CLSCompliant(false)] [CLSCompliant(false)]
public RequireAvatarNameAttribute(params string[] names) public RequireAvatarNameAttribute(params string[] names)
{ {
ArgumentNullException.ThrowIfNull(names); if (names is null)
{
throw new ArgumentNullException(nameof(names));
}
Names = names[..]; Names = names[..];
} }
@ -39,7 +47,11 @@ public sealed class RequireAvatarNameAttribute : PreExecutionCheckAttribute
/// <inheritdoc /> /// <inheritdoc />
protected internal override Task<bool> PerformAsync(CommandContext context) protected internal override Task<bool> PerformAsync(CommandContext context)
{ {
ArgumentNullException.ThrowIfNull(context); if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
return Task.FromResult(Names.Contains(context.Avatar.Name)); return Task.FromResult(Names.Contains(context.Avatar.Name));
} }
} }

View File

@ -8,7 +8,11 @@ public sealed class RequireBotAttribute : PreExecutionCheckAttribute
/// <inheritdoc /> /// <inheritdoc />
protected internal override Task<bool> PerformAsync(CommandContext context) protected internal override Task<bool> PerformAsync(CommandContext context)
{ {
ArgumentNullException.ThrowIfNull(context); if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
return Task.FromResult(context.Avatar.IsBot); return Task.FromResult(context.Avatar.IsBot);
} }
} }

View File

@ -8,7 +8,11 @@ public sealed class RequireBotOwnerAttribute : PreExecutionCheckAttribute
/// <inheritdoc /> /// <inheritdoc />
protected internal override Task<bool> PerformAsync(CommandContext context) protected internal override Task<bool> PerformAsync(CommandContext context)
{ {
ArgumentNullException.ThrowIfNull(context); if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
return Task.FromResult(context.Avatar.UserId == context.Client.CurrentUser?.Id); return Task.FromResult(context.Avatar.UserId == context.Client.CurrentUser?.Id);
} }
} }

View File

@ -8,7 +8,11 @@ public sealed class RequireHumanAttribute : PreExecutionCheckAttribute
/// <inheritdoc /> /// <inheritdoc />
protected internal override Task<bool> PerformAsync(CommandContext context) protected internal override Task<bool> PerformAsync(CommandContext context)
{ {
ArgumentNullException.ThrowIfNull(context); if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
return Task.FromResult(!context.Avatar.IsBot); return Task.FromResult(!context.Avatar.IsBot);
} }
} }

View File

@ -14,7 +14,11 @@ public sealed class RequireUserIdAttribute : PreExecutionCheckAttribute
/// <exception cref="ArgumentNullException"><paramref name="userIds" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="userIds" /> is <see langword="null" />.</exception>
public RequireUserIdAttribute(IEnumerable<int> userIds) public RequireUserIdAttribute(IEnumerable<int> userIds)
{ {
ArgumentNullException.ThrowIfNull(userIds); if (userIds is null)
{
throw new ArgumentNullException(nameof(userIds));
}
UserIds = userIds.ToArray(); UserIds = userIds.ToArray();
} }
@ -26,7 +30,11 @@ public sealed class RequireUserIdAttribute : PreExecutionCheckAttribute
[CLSCompliant(false)] [CLSCompliant(false)]
public RequireUserIdAttribute(params int[] userIds) public RequireUserIdAttribute(params int[] userIds)
{ {
ArgumentNullException.ThrowIfNull(userIds); if (userIds is null)
{
throw new ArgumentNullException(nameof(userIds));
}
UserIds = userIds[..]; UserIds = userIds[..];
} }
@ -39,7 +47,11 @@ public sealed class RequireUserIdAttribute : PreExecutionCheckAttribute
/// <inheritdoc /> /// <inheritdoc />
protected internal override Task<bool> PerformAsync(CommandContext context) protected internal override Task<bool> PerformAsync(CommandContext context)
{ {
ArgumentNullException.ThrowIfNull(context); if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
return Task.FromResult(UserIds.Contains(context.Avatar.UserId)); return Task.FromResult(UserIds.Contains(context.Avatar.UserId));
} }
} }

View File

@ -16,7 +16,11 @@ public sealed class RequireUserNameAttribute : PreExecutionCheckAttribute
/// <exception cref="ArgumentNullException"><paramref name="names" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="names" /> is <see langword="null" />.</exception>
public RequireUserNameAttribute(IEnumerable<string> names) public RequireUserNameAttribute(IEnumerable<string> names)
{ {
ArgumentNullException.ThrowIfNull(names); if (names is null)
{
throw new ArgumentNullException(nameof(names));
}
Names = names.ToArray(); Names = names.ToArray();
} }
@ -28,7 +32,11 @@ public sealed class RequireUserNameAttribute : PreExecutionCheckAttribute
[CLSCompliant(false)] [CLSCompliant(false)]
public RequireUserNameAttribute(params string[] names) public RequireUserNameAttribute(params string[] names)
{ {
ArgumentNullException.ThrowIfNull(names); if (names is null)
{
throw new ArgumentNullException(nameof(names));
}
Names = names[..]; Names = names[..];
} }
@ -41,7 +49,11 @@ public sealed class RequireUserNameAttribute : PreExecutionCheckAttribute
/// <inheritdoc /> /// <inheritdoc />
protected internal override async Task<bool> PerformAsync(CommandContext context) protected internal override async Task<bool> PerformAsync(CommandContext context)
{ {
ArgumentNullException.ThrowIfNull(context); if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
VirtualParadiseUser user = await context.Avatar.GetUserAsync().ConfigureAwait(false); VirtualParadiseUser user = await context.Avatar.GetUserAsync().ConfigureAwait(false);
return Names.Contains(user.Name); return Names.Contains(user.Name);
} }

View File

@ -33,8 +33,16 @@ public sealed class CommandsExtension : VirtualParadiseClientExtension
public CommandsExtension(VirtualParadiseClient client, CommandsExtensionConfiguration configuration) public CommandsExtension(VirtualParadiseClient client, CommandsExtensionConfiguration configuration)
: base(client) : base(client)
{ {
ArgumentNullException.ThrowIfNull(client); if (client is null)
ArgumentNullException.ThrowIfNull(configuration); {
throw new ArgumentNullException(nameof(client));
}
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
_configuration = configuration; _configuration = configuration;
_configuration.Services ??= client.Services; _configuration.Services ??= client.Services;
@ -64,7 +72,10 @@ public sealed class CommandsExtension : VirtualParadiseClientExtension
/// </exception> /// </exception>
public void RegisterCommands(Assembly assembly) public void RegisterCommands(Assembly assembly)
{ {
ArgumentNullException.ThrowIfNull(assembly); if (assembly is null)
{
throw new ArgumentNullException(nameof(assembly));
}
foreach (Type type in assembly.GetTypes()) foreach (Type type in assembly.GetTypes())
{ {
@ -136,7 +147,10 @@ public sealed class CommandsExtension : VirtualParadiseClientExtension
/// </exception> /// </exception>
public void RegisterCommands(Type moduleType) public void RegisterCommands(Type moduleType)
{ {
ArgumentNullException.ThrowIfNull(moduleType); if (moduleType is null)
{
throw new ArgumentNullException(nameof(moduleType));
}
if (moduleType.IsAbstract) if (moduleType.IsAbstract)
{ {
@ -164,7 +178,10 @@ public sealed class CommandsExtension : VirtualParadiseClientExtension
/// <inheritdoc /> /// <inheritdoc />
protected internal override Task OnMessageReceived(VirtualParadiseMessage message) protected internal override Task OnMessageReceived(VirtualParadiseMessage message)
{ {
ArgumentNullException.ThrowIfNull(message); if (message is null)
{
throw new ArgumentNullException(nameof(message));
}
if (message.Type != MessageType.ChatMessage) if (message.Type != MessageType.ChatMessage)
{ {

View File

@ -14,7 +14,11 @@ public static class VirtualParadiseClientExtensions
/// <exception cref="ArgumentNullException"><paramref name="client" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="client" /> is <see langword="null" />.</exception>
public static CommandsExtension UseCommands(this VirtualParadiseClient client, CommandsExtensionConfiguration configuration) public static CommandsExtension UseCommands(this VirtualParadiseClient client, CommandsExtensionConfiguration configuration)
{ {
ArgumentNullException.ThrowIfNull(client); if (client is null)
{
throw new ArgumentNullException(nameof(client));
}
return client.AddExtension<CommandsExtension>(configuration); return client.AddExtension<CommandsExtension>(configuration);
} }
} }

View File

@ -224,7 +224,11 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
/// <remarks>Passing <see langword="null" /> to <paramref name="name" /> will hide the name from the recipient.</remarks> /// <remarks>Passing <see langword="null" /> to <paramref name="name" /> will hide the name from the recipient.</remarks>
public Task<VirtualParadiseMessage> SendMessageAsync(string? name, string message, FontStyle fontStyle, Color color) public Task<VirtualParadiseMessage> SendMessageAsync(string? name, string message, FontStyle fontStyle, Color color)
{ {
ArgumentNullException.ThrowIfNull(message); if (message is null)
{
throw new ArgumentNullException(nameof(message));
}
if (string.IsNullOrWhiteSpace(message)) if (string.IsNullOrWhiteSpace(message))
{ {
throw new ArgumentException(ExceptionMessages.ValueCannotBeEmpty, nameof(message)); throw new ArgumentException(ExceptionMessages.ValueCannotBeEmpty, nameof(message));
@ -282,7 +286,10 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
/// <exception cref="ArgumentNullException"><paramref name="uri" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="uri" /> is <see langword="null" />.</exception>
public Task SendUriAsync(Uri uri, UriTarget target = UriTarget.Browser) public Task SendUriAsync(Uri uri, UriTarget target = UriTarget.Browser)
{ {
ArgumentNullException.ThrowIfNull(uri); if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
// ReSharper disable once InconsistentlySynchronizedField // ReSharper disable once InconsistentlySynchronizedField
if (this == _client.CurrentAvatar) if (this == _client.CurrentAvatar)
@ -306,7 +313,10 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
/// <exception cref="UnauthorizedAccessException">The client does not have permission to modify world settings.</exception> /// <exception cref="UnauthorizedAccessException">The client does not have permission to modify world settings.</exception>
public async Task SendWorldSettings(Action<WorldSettingsBuilder> action) public async Task SendWorldSettings(Action<WorldSettingsBuilder> action)
{ {
ArgumentNullException.ThrowIfNull(action); if (action is null)
{
throw new ArgumentNullException(nameof(action));
}
// ReSharper disable once InconsistentlySynchronizedField // ReSharper disable once InconsistentlySynchronizedField
var builder = new WorldSettingsBuilder(_client, Session); var builder = new WorldSettingsBuilder(_client, Session);
@ -323,7 +333,11 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
/// <exception cref="ArgumentNullException"><paramref name="world" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="world" /> is <see langword="null" />.</exception>
public Task TeleportAsync(VirtualParadiseWorld world, Vector3d position) public Task TeleportAsync(VirtualParadiseWorld world, Vector3d position)
{ {
ArgumentNullException.ThrowIfNull(world); if (world is null)
{
throw new ArgumentNullException(nameof(world));
}
return TeleportAsync(world.Name, position, Rotation.None); return TeleportAsync(world.Name, position, Rotation.None);
} }
@ -336,7 +350,11 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
/// <exception cref="ArgumentNullException"><paramref name="world" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="world" /> is <see langword="null" />.</exception>
public Task TeleportAsync(VirtualParadiseWorld world, Vector3d position, Rotation rotation) public Task TeleportAsync(VirtualParadiseWorld world, Vector3d position, Rotation rotation)
{ {
ArgumentNullException.ThrowIfNull(world); if (world is null)
{
throw new ArgumentNullException(nameof(world));
}
return TeleportAsync(world.Name, position, rotation); return TeleportAsync(world.Name, position, rotation);
} }
@ -358,15 +376,15 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
/// <param name="rotation">The rotation to which this avatar should be teleported.</param> /// <param name="rotation">The rotation to which this avatar should be teleported.</param>
public async Task TeleportAsync(string world, Vector3d position, Rotation rotation) public async Task TeleportAsync(string world, Vector3d position, Rotation rotation)
{ {
ArgumentNullException.ThrowIfNull(world); if (world is null)
#if NET7_0_OR_GREATER {
ArgumentException.ThrowIfNullOrEmpty(world); throw new ArgumentNullException(nameof(world));
#else }
if (string.IsNullOrEmpty(world)) if (string.IsNullOrEmpty(world))
{ {
throw new ArgumentException(ExceptionMessages.ValueCannotBeEmpty, nameof(world)); throw new ArgumentException(ExceptionMessages.ValueCannotBeEmpty, nameof(world));
} }
#endif
// ReSharper disable InconsistentlySynchronizedField // ReSharper disable InconsistentlySynchronizedField
bool isSelf = this == _client.CurrentAvatar; bool isSelf = this == _client.CurrentAvatar;

View File

@ -52,7 +52,10 @@ public class VirtualParadiseModelObject : VirtualParadiseObject
/// </exception> /// </exception>
public async Task ModifyAsync(Action<VirtualParadiseModelObjectBuilder> action) public async Task ModifyAsync(Action<VirtualParadiseModelObjectBuilder> action)
{ {
ArgumentNullException.ThrowIfNull(action); if (action is null)
{
throw new ArgumentNullException(nameof(action));
}
var taskCompletionSource = new TaskCompletionSource<ReasonCode>(); var taskCompletionSource = new TaskCompletionSource<ReasonCode>();
var builder = new VirtualParadiseModelObjectBuilder(Client, this, ObjectBuilderMode.Modify); var builder = new VirtualParadiseModelObjectBuilder(Client, this, ObjectBuilderMode.Modify);

View File

@ -20,7 +20,11 @@ public abstract class VirtualParadiseObject : IEquatable<VirtualParadiseObject>
/// <exception cref="ArgumentNullException"><paramref name="client" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="client" /> is <see langword="null" />.</exception>
protected internal VirtualParadiseObject(VirtualParadiseClient client, int id) protected internal VirtualParadiseObject(VirtualParadiseClient client, int id)
{ {
ArgumentNullException.ThrowIfNull(client); if (client is null)
{
throw new ArgumentNullException(nameof(client));
}
Client = client; Client = client;
Id = id; Id = id;
} }
@ -237,7 +241,10 @@ public abstract class VirtualParadiseObject : IEquatable<VirtualParadiseObject>
/// <param name="builder">The builder whose values to extract.</param> /// <param name="builder">The builder whose values to extract.</param>
protected internal virtual void ExtractFromBuilder(VirtualParadiseObjectBuilder builder) protected internal virtual void ExtractFromBuilder(VirtualParadiseObjectBuilder builder)
{ {
ArgumentNullException.ThrowIfNull(builder); if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}
Location location = Location; Location location = Location;
Vector3d position = builder.Position.ValueOr(location.Position); Vector3d position = builder.Position.ValueOr(location.Position);
@ -256,7 +263,11 @@ public abstract class VirtualParadiseObject : IEquatable<VirtualParadiseObject>
/// <exception cref="ArgumentNullException"><paramref name="virtualParadiseObject" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="virtualParadiseObject" /> is <see langword="null" />.</exception>
protected internal virtual void ExtractFromOther(VirtualParadiseObject virtualParadiseObject) protected internal virtual void ExtractFromOther(VirtualParadiseObject virtualParadiseObject)
{ {
ArgumentNullException.ThrowIfNull(virtualParadiseObject); if (virtualParadiseObject is null)
{
throw new ArgumentNullException(nameof(virtualParadiseObject));
}
Location = virtualParadiseObject.Location; Location = virtualParadiseObject.Location;
ModificationTimestamp = virtualParadiseObject.ModificationTimestamp; ModificationTimestamp = virtualParadiseObject.ModificationTimestamp;
Owner = virtualParadiseObject.Owner; Owner = virtualParadiseObject.Owner;

View File

@ -123,7 +123,10 @@ public sealed class VirtualParadiseWorld : IEquatable<VirtualParadiseWorld>
/// <exception cref="UnauthorizedAccessException">The client does not have permission to modify world settings.</exception> /// <exception cref="UnauthorizedAccessException">The client does not have permission to modify world settings.</exception>
public async Task ModifyAsync(Action<WorldSettingsBuilder> action) public async Task ModifyAsync(Action<WorldSettingsBuilder> action)
{ {
ArgumentNullException.ThrowIfNull(action); if (action is null)
{
throw new ArgumentNullException(nameof(action));
}
var builder = new WorldSettingsBuilder(_client); var builder = new WorldSettingsBuilder(_client);
await Task.Run(() => action(builder)).ConfigureAwait(false); await Task.Run(() => action(builder)).ConfigureAwait(false);

View File

@ -17,14 +17,26 @@ internal static class DependencyInjectionUtility
public static object CreateInstance(Type type, VirtualParadiseClient client) public static object CreateInstance(Type type, VirtualParadiseClient client)
{ {
ArgumentNullException.ThrowIfNull(type); if (type is null)
ArgumentNullException.ThrowIfNull(client); {
throw new ArgumentNullException(nameof(type));
}
if (client is null)
{
throw new ArgumentNullException(nameof(client));
}
return CreateInstance(type, client.Services); return CreateInstance(type, client.Services);
} }
public static object CreateInstance(Type type, IServiceProvider? serviceProvider = null) public static object CreateInstance(Type type, IServiceProvider? serviceProvider = null)
{ {
ArgumentNullException.ThrowIfNull(type); if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
object? instance; object? instance;
TypeInfo typeInfo = type.GetTypeInfo(); TypeInfo typeInfo = type.GetTypeInfo();

View File

@ -46,7 +46,10 @@ public sealed partial class VirtualParadiseClient
/// </exception> /// </exception>
public VirtualParadiseClientExtension AddExtension(Type type, params object?[]? arguments) public VirtualParadiseClientExtension AddExtension(Type type, params object?[]? arguments)
{ {
ArgumentNullException.ThrowIfNull(type); if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
if (!type.IsSubclassOf(typeof(VirtualParadiseClientExtension))) if (!type.IsSubclassOf(typeof(VirtualParadiseClientExtension)))
{ {
@ -85,7 +88,10 @@ public sealed partial class VirtualParadiseClient
/// <exception cref="InvalidOperationException">No extension with the specified type is added to this client.</exception> /// <exception cref="InvalidOperationException">No extension with the specified type is added to this client.</exception>
public VirtualParadiseClientExtension GetExtension(Type type) public VirtualParadiseClientExtension GetExtension(Type type)
{ {
ArgumentNullException.ThrowIfNull(type); if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
VirtualParadiseClientExtension? result = _extensions.Find(e => e.GetType() == type); VirtualParadiseClientExtension? result = _extensions.Find(e => e.GetType() == type);
if (result is null) if (result is null)
@ -126,7 +132,10 @@ public sealed partial class VirtualParadiseClient
/// <exception cref="InvalidOperationException">No extension with the specified type is added to this client.</exception> /// <exception cref="InvalidOperationException">No extension with the specified type is added to this client.</exception>
public bool TryGetExtension(Type type, [NotNullWhen(true)] out VirtualParadiseClientExtension? extension) public bool TryGetExtension(Type type, [NotNullWhen(true)] out VirtualParadiseClientExtension? extension)
{ {
ArgumentNullException.ThrowIfNull(type); if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
extension = _extensions.Find(e => e.GetType() == type); extension = _extensions.Find(e => e.GetType() == type);
return extension is not null; return extension is not null;

View File

@ -160,7 +160,10 @@ public sealed partial class VirtualParadiseClient
private VirtualParadiseObject AddOrUpdateObject(VirtualParadiseObject obj) private VirtualParadiseObject AddOrUpdateObject(VirtualParadiseObject obj)
{ {
ArgumentNullException.ThrowIfNull(obj); if (obj is null)
{
throw new ArgumentNullException(nameof(obj));
}
return _objects.AddOrUpdate(obj.Id, obj, (_, existing) => return _objects.AddOrUpdate(obj.Id, obj, (_, existing) =>
{ {

View File

@ -46,7 +46,11 @@ public sealed partial class VirtualParadiseClient : IDisposable
/// <exception cref="ArgumentNullException"><paramref name="configuration" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="configuration" /> is <see langword="null" />.</exception>
public VirtualParadiseClient(VirtualParadiseConfiguration configuration) public VirtualParadiseClient(VirtualParadiseConfiguration configuration)
{ {
ArgumentNullException.ThrowIfNull(configuration); if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
Services = configuration.Services; Services = configuration.Services;
_configuration = new VirtualParadiseConfiguration(configuration); _configuration = new VirtualParadiseConfiguration(configuration);
Initialize(); Initialize();
@ -298,7 +302,11 @@ public sealed partial class VirtualParadiseClient : IDisposable
/// <exception cref="TimeoutException">Connection to the world server timed out.</exception> /// <exception cref="TimeoutException">Connection to the world server timed out.</exception>
public async Task EnterAsync(VirtualParadiseWorld world) public async Task EnterAsync(VirtualParadiseWorld world)
{ {
ArgumentNullException.ThrowIfNull(world); if (world is null)
{
throw new ArgumentNullException(nameof(world));
}
await EnterAsync(world.Name).ConfigureAwait(false); await EnterAsync(world.Name).ConfigureAwait(false);
} }
@ -317,7 +325,10 @@ public sealed partial class VirtualParadiseClient : IDisposable
/// <exception cref="TimeoutException">Connection to the world server timed out.</exception> /// <exception cref="TimeoutException">Connection to the world server timed out.</exception>
public async Task<VirtualParadiseWorld> EnterAsync(string worldName) public async Task<VirtualParadiseWorld> EnterAsync(string worldName)
{ {
ArgumentNullException.ThrowIfNull(worldName); if (worldName is null)
{
throw new ArgumentNullException(nameof(worldName));
}
if (CurrentWorld is not null) if (CurrentWorld is not null)
{ {
@ -555,7 +566,11 @@ public sealed partial class VirtualParadiseClient : IDisposable
/// </exception> /// </exception>
public Task<VirtualParadiseMessage> SendMessageAsync(string message) public Task<VirtualParadiseMessage> SendMessageAsync(string message)
{ {
ArgumentNullException.ThrowIfNull(message); if (message is null)
{
throw new ArgumentNullException(nameof(message));
}
if (string.IsNullOrWhiteSpace(message)) if (string.IsNullOrWhiteSpace(message))
{ {
throw new ArgumentException(ExceptionMessages.ValueCannotBeEmpty, nameof(message)); throw new ArgumentException(ExceptionMessages.ValueCannotBeEmpty, nameof(message));
@ -628,7 +643,11 @@ public sealed partial class VirtualParadiseClient : IDisposable
/// </exception> /// </exception>
public Task<VirtualParadiseMessage> SendMessageAsync(string? name, string message, FontStyle fontStyle, Color color) public Task<VirtualParadiseMessage> SendMessageAsync(string? name, string message, FontStyle fontStyle, Color color)
{ {
ArgumentNullException.ThrowIfNull(message); if (message is null)
{
throw new ArgumentNullException(nameof(message));
}
if (string.IsNullOrWhiteSpace(message)) if (string.IsNullOrWhiteSpace(message))
{ {
throw new ArgumentException(ExceptionMessages.ValueCannotBeEmpty, nameof(message)); throw new ArgumentException(ExceptionMessages.ValueCannotBeEmpty, nameof(message));