From b4deeaf92c38716440559227080cba1c0260c131 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Wed, 30 Nov 2022 18:06:23 +0000 Subject: [PATCH] Use statement bodies --- VpSharp/src/Cell.cs | 25 +++++++-- VpSharp/src/Entities/VirtualParadiseAvatar.cs | 5 +- VpSharp/src/Internal/ThrowHelper.cs | 54 +++++++++++++----- VpSharp/src/InviteRequest.cs | 55 +++++++++++++------ VpSharp/src/JoinRequest.cs | 30 ++++++++-- VpSharp/src/Vector3d.cs | 35 +++++++++--- 6 files changed, 156 insertions(+), 48 deletions(-) diff --git a/VpSharp/src/Cell.cs b/VpSharp/src/Cell.cs index 5b54aee..cda8fdd 100644 --- a/VpSharp/src/Cell.cs +++ b/VpSharp/src/Cell.cs @@ -38,7 +38,10 @@ public readonly struct Cell : IEquatable, IFormattable /// The first cell to compare. /// The second cell to compare. /// if the two cells are equal; otherwise, . - public static bool operator ==(Cell left, Cell right) => left.Equals(right); + public static bool operator ==(Cell left, Cell right) + { + return left.Equals(right); + } /// /// Returns a value indicating whether the two given cells are equal. @@ -46,7 +49,10 @@ public readonly struct Cell : IEquatable, IFormattable /// The first cell to compare. /// The second cell to compare. /// if the two cells are equal; otherwise, . - public static bool operator !=(Cell left, Cell right) => !left.Equals(right); + public static bool operator !=(Cell left, Cell right) + { + return !left.Equals(right); + } /// /// Explicitly converts an instance of to an instance of . @@ -148,13 +154,22 @@ public readonly struct Cell : IEquatable, IFormattable /// /// The cell to compare with this instance. /// if the two cells are equal; otherwise, . - public bool Equals(Cell other) => X == other.X && Z == other.Z; + public bool Equals(Cell other) + { + return X == other.X && Z == other.Z; + } /// - public override bool Equals(object obj) => obj is Cell other && Equals(other); + public override bool Equals(object? obj) + { + return obj is Cell other && Equals(other); + } /// - public override int GetHashCode() => HashCode.Combine(X, Z); + public override int GetHashCode() + { + return HashCode.Combine(X, Z); + } /// /// Returns a representing this instance. diff --git a/VpSharp/src/Entities/VirtualParadiseAvatar.cs b/VpSharp/src/Entities/VirtualParadiseAvatar.cs index f953171..ee88b68 100644 --- a/VpSharp/src/Entities/VirtualParadiseAvatar.cs +++ b/VpSharp/src/Entities/VirtualParadiseAvatar.cs @@ -30,7 +30,10 @@ public sealed class VirtualParadiseAvatar : IEquatable /// Gets a value indicating whether this avatar is a bot. /// /// if this avatar is a bot; otherwise, . - public bool IsBot => Name is {Length: > 1} name && name[0] == '[' && name[^1] == ']'; + public bool IsBot + { + get => Name is {Length: > 1} name && name[0] == '[' && name[^1] == ']'; + } /// /// Gets the location of this avatar. diff --git a/VpSharp/src/Internal/ThrowHelper.cs b/VpSharp/src/Internal/ThrowHelper.cs index c9cfe46..95fe284 100644 --- a/VpSharp/src/Internal/ThrowHelper.cs +++ b/VpSharp/src/Internal/ThrowHelper.cs @@ -1,34 +1,62 @@ -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; using VpSharp.Exceptions; namespace VpSharp.Internal; internal static class ThrowHelper { - public static InvalidOperationException CannotUseSelfException() => new(ExceptionMessages.CannotUseSelf); + public static InvalidOperationException CannotUseSelfException() + { + return new InvalidOperationException(ExceptionMessages.CannotUseSelf); + } [DoesNotReturn] - public static void ThrowCannotUseSelfException() => throw CannotUseSelfException(); + public static void ThrowCannotUseSelfException() + { + throw CannotUseSelfException(); + } - public static InvalidOperationException NotInWorldException() => new(ExceptionMessages.NotInWorld); + public static InvalidOperationException NotInWorldException() + { + return new InvalidOperationException(ExceptionMessages.NotInWorld); + } [DoesNotReturn] - public static void ThrowNotInWorldException() => throw NotInWorldException(); + public static void ThrowNotInWorldException() + { + throw NotInWorldException(); + } - public static ObjectNotFoundException ObjectNotFoundException() => new(ExceptionMessages.ObjectNotFound); + public static ObjectNotFoundException ObjectNotFoundException() + { + return new ObjectNotFoundException(ExceptionMessages.ObjectNotFound); + } [DoesNotReturn] - public static void ThrowObjectNotFoundException() => throw ObjectNotFoundException(); + public static void ThrowObjectNotFoundException() + { + throw ObjectNotFoundException(); + } - public static ArgumentException StringTooLongException(string paramName) => - new(ExceptionMessages.StringTooLong, paramName); + public static ArgumentException StringTooLongException(string paramName) + { + return new ArgumentException(ExceptionMessages.StringTooLong, paramName); + } [DoesNotReturn] - public static void ThrowStringTooLongException(string paramName) => throw StringTooLongException(paramName); + public static void ThrowStringTooLongException(string paramName) + { + throw StringTooLongException(paramName); + } - public static ArgumentOutOfRangeException ZeroThroughOneException(string paramName) => - new(paramName, ExceptionMessages.ZeroThroughOne); + public static ArgumentOutOfRangeException ZeroThroughOneException(string paramName) + { + return new ArgumentOutOfRangeException(paramName, ExceptionMessages.ZeroThroughOne); + } [DoesNotReturn] - public static void ThrowZeroThroughOneException(string paramName) => throw ZeroThroughOneException(paramName); + public static void ThrowZeroThroughOneException(string paramName) + { + throw ZeroThroughOneException(paramName); + } } diff --git a/VpSharp/src/InviteRequest.cs b/VpSharp/src/InviteRequest.cs index 9de44ae..a107e4d 100644 --- a/VpSharp/src/InviteRequest.cs +++ b/VpSharp/src/InviteRequest.cs @@ -43,20 +43,26 @@ public sealed class InviteRequest : IEquatable /// The user which sent the request. public VirtualParadiseUser User { get; } - /// - public bool Equals(InviteRequest? other) + /// + /// Returns a value indicating whether two instances are equal. + /// + /// The first instance. + /// The second instance. + /// if the two instances are equal; otherwise, . + public static bool operator ==(InviteRequest? left, InviteRequest? right) { - if (ReferenceEquals(null, other)) - { - return false; - } + return Equals(left, right); + } - if (ReferenceEquals(this, other)) - { - return true; - } - - return _requestId == other._requestId && _client.Equals(other._client); + /// + /// Returns a value indicating whether two instances are not equal. + /// + /// The first instance. + /// The second instance. + /// if the two instances are not equal; otherwise, . + public static bool operator !=(InviteRequest? left, InviteRequest? right) + { + return !Equals(left, right); } /// @@ -93,6 +99,22 @@ public sealed class InviteRequest : IEquatable return Task.CompletedTask; } + /// + public bool Equals(InviteRequest? other) + { + if (ReferenceEquals(null, other)) + { + return false; + } + + if (ReferenceEquals(this, other)) + { + return true; + } + + return _requestId == other._requestId && _client.Equals(other._client); + } + /// public override bool Equals(object? obj) { @@ -105,9 +127,8 @@ public sealed class InviteRequest : IEquatable } /// - public override int GetHashCode() => HashCode.Combine(_client, _requestId); - - public static bool operator ==(InviteRequest left, InviteRequest right) => Equals(left, right); - - public static bool operator !=(InviteRequest left, InviteRequest right) => !Equals(left, right); + public override int GetHashCode() + { + return HashCode.Combine(_client, _requestId); + } } diff --git a/VpSharp/src/JoinRequest.cs b/VpSharp/src/JoinRequest.cs index 51975e2..8c5ef71 100644 --- a/VpSharp/src/JoinRequest.cs +++ b/VpSharp/src/JoinRequest.cs @@ -1,4 +1,4 @@ -using VpSharp.Entities; +using VpSharp.Entities; using VpSharp.Extensions; using VpSharp.Internal; @@ -32,9 +32,27 @@ public sealed class JoinRequest : IEquatable /// The user which sent the request. public VirtualParadiseUser User { get; } - public static bool operator ==(JoinRequest left, JoinRequest right) => Equals(left, right); + /// + /// Returns a value indicating whether two instances are equal. + /// + /// The first instance. + /// The second instance. + /// if the two instances are equal; otherwise, . + public static bool operator ==(JoinRequest? left, JoinRequest? right) + { + return Equals(left, right); + } - public static bool operator !=(JoinRequest left, JoinRequest right) => !Equals(left, right); + /// + /// Returns a value indicating whether two instances are not equal. + /// + /// The first instance. + /// The second instance. + /// if the two instances are not equal; otherwise, . + public static bool operator !=(JoinRequest? left, JoinRequest? right) + { + return !Equals(left, right); + } /// /// Accepts this join request. @@ -75,7 +93,6 @@ public sealed class JoinRequest : IEquatable return Task.CompletedTask; } - /// public bool Equals(JoinRequest? other) { @@ -104,5 +121,8 @@ public sealed class JoinRequest : IEquatable } /// - public override int GetHashCode() => HashCode.Combine(_client, _requestId); + public override int GetHashCode() + { + return HashCode.Combine(_client, _requestId); + } } diff --git a/VpSharp/src/Vector3d.cs b/VpSharp/src/Vector3d.cs index fbf9242..20a555c 100644 --- a/VpSharp/src/Vector3d.cs +++ b/VpSharp/src/Vector3d.cs @@ -79,14 +79,20 @@ public struct Vector3d : IEquatable, IFormattable /// /// The length of the vector. /// - public double Length => Distance(this, Zero); + public double Length + { + get => Distance(this, Zero); + } /// /// Gets the squared length of the vector. /// /// The length of the vector, squared. /// - public double LengthSquared => DistanceSquared(this, Zero); + public double LengthSquared + { + get => DistanceSquared(this, Zero); + } /// /// Gets or sets the X component of the vector. @@ -227,7 +233,10 @@ public struct Vector3d : IEquatable, IFormattable /// The first vector to compare. /// The second vector to compare. /// if the two vectors are equal; otherwise, . - public static bool operator ==(Vector3d left, Vector3d right) => left.Equals(right); + public static bool operator ==(in Vector3d left, in Vector3d right) + { + return left.Equals(right); + } /// /// Returns a value indicating whether the two given vectors are not equal. @@ -235,7 +244,10 @@ public struct Vector3d : IEquatable, IFormattable /// The first vector to compare. /// The second vector to compare. /// if the two vectors are not equal; otherwise, . - public static bool operator !=(Vector3d left, Vector3d right) => !left.Equals(right); + public static bool operator !=(in Vector3d left, in Vector3d right) + { + return !left.Equals(right); + } /// /// Implicitly converts a to a new instance of , by implicitly converting @@ -482,13 +494,22 @@ public struct Vector3d : IEquatable, IFormattable /// /// The vector to compare with this instance. /// if the two vectors are equal; otherwise, . - public readonly bool Equals(Vector3d other) => X.Equals(other.X) && Y.Equals(other.Y) && Z.Equals(other.Z); + public readonly bool Equals(Vector3d other) + { + return X.Equals(other.X) && Y.Equals(other.Y) && Z.Equals(other.Z); + } /// - public override readonly bool Equals(object? obj) => obj is Vector3d other && Equals(other); + public override readonly bool Equals(object? obj) + { + return obj is Vector3d other && Equals(other); + } /// - public override readonly int GetHashCode() => HashCode.Combine(X, Y, Z); + public override readonly int GetHashCode() + { + return HashCode.Combine(X, Y, Z); + } /// /// Returns a representing this instance.