From cfd1e4c2082b976b660e23a3f9e7d4e4966ac83c Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Wed, 30 Nov 2022 18:16:37 +0000 Subject: [PATCH] Validate non-null arguments for public API --- VpSharp.Commands/CommandsExtension.cs | 1 + .../VirtualParadiseClientExtensions.cs | 2 ++ VpSharp/src/Entities/VirtualParadiseAvatar.cs | 14 ++++++++++++++ 3 files changed, 17 insertions(+) diff --git a/VpSharp.Commands/CommandsExtension.cs b/VpSharp.Commands/CommandsExtension.cs index 3009cee..ebe8fee 100644 --- a/VpSharp.Commands/CommandsExtension.cs +++ b/VpSharp.Commands/CommandsExtension.cs @@ -134,6 +134,7 @@ public sealed class CommandsExtension : VirtualParadiseClientExtension /// protected override Task OnMessageReceived(MessageReceivedEventArgs args) { + ArgumentNullException.ThrowIfNull(args); var message = args.Message; if (message.Type != MessageType.ChatMessage) diff --git a/VpSharp.Commands/VirtualParadiseClientExtensions.cs b/VpSharp.Commands/VirtualParadiseClientExtensions.cs index d8e2e06..43e6a31 100644 --- a/VpSharp.Commands/VirtualParadiseClientExtensions.cs +++ b/VpSharp.Commands/VirtualParadiseClientExtensions.cs @@ -11,8 +11,10 @@ public static class VirtualParadiseClientExtensions /// The . /// The configuration required for the extensions. /// The commands extension instance. + /// is . public static CommandsExtension UseCommands(this VirtualParadiseClient client, CommandsExtensionConfiguration configuration) { + ArgumentNullException.ThrowIfNull(client); return client.AddExtension(configuration); } } diff --git a/VpSharp/src/Entities/VirtualParadiseAvatar.cs b/VpSharp/src/Entities/VirtualParadiseAvatar.cs index 015a374..0d1461f 100644 --- a/VpSharp/src/Entities/VirtualParadiseAvatar.cs +++ b/VpSharp/src/Entities/VirtualParadiseAvatar.cs @@ -292,8 +292,10 @@ public sealed class VirtualParadiseAvatar : IEquatable /// /// The name of the world to which this avatar should be teleported. /// The position to which this avatar should be teleported. + /// is . public Task TeleportAsync(VirtualParadiseWorld world, Vector3d position) { + ArgumentNullException.ThrowIfNull(world); return TeleportAsync(world.Name, position, Quaternion.Identity); } @@ -303,8 +305,10 @@ public sealed class VirtualParadiseAvatar : IEquatable /// The name of the world to which this avatar should be teleported. /// The position to which this avatar should be teleported. /// The rotation to which this avatar should be teleported. + /// is . public Task TeleportAsync(VirtualParadiseWorld world, Vector3d position, Quaternion rotation) { + ArgumentNullException.ThrowIfNull(world); return TeleportAsync(world.Name, position, rotation); } @@ -326,6 +330,16 @@ public sealed class VirtualParadiseAvatar : IEquatable /// The rotation to which this avatar should be teleported. public async Task TeleportAsync(string world, Vector3d position, Quaternion rotation) { + ArgumentNullException.ThrowIfNull(world); +#if NET7_0_OR_GREATER + ArgumentException.ThrowIfNullOrEmpty(world); +#else + if (string.IsNullOrEmpty(world)) + { + throw new ArgumentException("World cannot be empty"); + } +#endif + // ReSharper disable InconsistentlySynchronizedField bool isSelf = this == _client.CurrentAvatar; bool isNewWorld = world != Location.World.Name;