1
0
mirror of https://github.com/oliverbooth/VpSharp synced 2024-11-10 04:55:41 +00:00

Use statement bodies

This commit is contained in:
Oliver Booth 2022-11-30 18:06:23 +00:00
parent 99c08f33ed
commit b4deeaf92c
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
6 changed files with 156 additions and 48 deletions

View File

@ -38,7 +38,10 @@ public readonly struct Cell : IEquatable<Cell>, IFormattable
/// <param name="left">The first cell to compare.</param> /// <param name="left">The first cell to compare.</param>
/// <param name="right">The second cell to compare.</param> /// <param name="right">The second cell to compare.</param>
/// <returns><see langword="true" /> if the two cells are equal; otherwise, <see langword="false" />.</returns> /// <returns><see langword="true" /> if the two cells are equal; otherwise, <see langword="false" />.</returns>
public static bool operator ==(Cell left, Cell right) => left.Equals(right); public static bool operator ==(Cell left, Cell right)
{
return left.Equals(right);
}
/// <summary> /// <summary>
/// Returns a value indicating whether the two given cells are equal. /// Returns a value indicating whether the two given cells are equal.
@ -46,7 +49,10 @@ public readonly struct Cell : IEquatable<Cell>, IFormattable
/// <param name="left">The first cell to compare.</param> /// <param name="left">The first cell to compare.</param>
/// <param name="right">The second cell to compare.</param> /// <param name="right">The second cell to compare.</param>
/// <returns><see langword="true" /> if the two cells are equal; otherwise, <see langword="false" />.</returns> /// <returns><see langword="true" /> if the two cells are equal; otherwise, <see langword="false" />.</returns>
public static bool operator !=(Cell left, Cell right) => !left.Equals(right); public static bool operator !=(Cell left, Cell right)
{
return !left.Equals(right);
}
/// <summary> /// <summary>
/// Explicitly converts an instance of <see cref="Vector2" /> to an instance of <see cref="Cell" />. /// Explicitly converts an instance of <see cref="Vector2" /> to an instance of <see cref="Cell" />.
@ -148,13 +154,22 @@ public readonly struct Cell : IEquatable<Cell>, IFormattable
/// </summary> /// </summary>
/// <param name="other">The cell to compare with this instance.</param> /// <param name="other">The cell to compare with this instance.</param>
/// <returns><see langword="true" /> if the two cells are equal; otherwise, <see langword="false" />.</returns> /// <returns><see langword="true" /> if the two cells are equal; otherwise, <see langword="false" />.</returns>
public bool Equals(Cell other) => X == other.X && Z == other.Z; public bool Equals(Cell other)
{
return X == other.X && Z == other.Z;
}
/// <inheritdoc /> /// <inheritdoc />
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);
}
/// <inheritdoc /> /// <inheritdoc />
public override int GetHashCode() => HashCode.Combine(X, Z); public override int GetHashCode()
{
return HashCode.Combine(X, Z);
}
/// <summary> /// <summary>
/// Returns a <see cref="string" /> representing this <see cref="Vector3d" /> instance. /// Returns a <see cref="string" /> representing this <see cref="Vector3d" /> instance.

View File

@ -30,7 +30,10 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
/// Gets a value indicating whether this avatar is a bot. /// Gets a value indicating whether this avatar is a bot.
/// </summary> /// </summary>
/// <value><see langword="true" /> if this avatar is a bot; otherwise, <see langword="false" />.</value> /// <value><see langword="true" /> if this avatar is a bot; otherwise, <see langword="false" />.</value>
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] == ']';
}
/// <summary> /// <summary>
/// Gets the location of this avatar. /// Gets the location of this avatar.

View File

@ -1,34 +1,62 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using VpSharp.Exceptions; using VpSharp.Exceptions;
namespace VpSharp.Internal; namespace VpSharp.Internal;
internal static class ThrowHelper internal static class ThrowHelper
{ {
public static InvalidOperationException CannotUseSelfException() => new(ExceptionMessages.CannotUseSelf); public static InvalidOperationException CannotUseSelfException()
{
[DoesNotReturn] return new InvalidOperationException(ExceptionMessages.CannotUseSelf);
public static void ThrowCannotUseSelfException() => throw CannotUseSelfException(); }
public static InvalidOperationException NotInWorldException() => new(ExceptionMessages.NotInWorld); [DoesNotReturn]
public static void ThrowCannotUseSelfException()
[DoesNotReturn] {
public static void ThrowNotInWorldException() => throw NotInWorldException(); throw CannotUseSelfException();
}
public static ObjectNotFoundException ObjectNotFoundException() => new(ExceptionMessages.ObjectNotFound);
public static InvalidOperationException NotInWorldException()
[DoesNotReturn] {
public static void ThrowObjectNotFoundException() => throw ObjectNotFoundException(); return new InvalidOperationException(ExceptionMessages.NotInWorld);
}
public static ArgumentException StringTooLongException(string paramName) =>
new(ExceptionMessages.StringTooLong, paramName); [DoesNotReturn]
public static void ThrowNotInWorldException()
[DoesNotReturn] {
public static void ThrowStringTooLongException(string paramName) => throw StringTooLongException(paramName); throw NotInWorldException();
}
public static ArgumentOutOfRangeException ZeroThroughOneException(string paramName) =>
new(paramName, ExceptionMessages.ZeroThroughOne); public static ObjectNotFoundException ObjectNotFoundException()
{
[DoesNotReturn] return new ObjectNotFoundException(ExceptionMessages.ObjectNotFound);
public static void ThrowZeroThroughOneException(string paramName) => throw ZeroThroughOneException(paramName); }
[DoesNotReturn]
public static void ThrowObjectNotFoundException()
{
throw ObjectNotFoundException();
}
public static ArgumentException StringTooLongException(string paramName)
{
return new ArgumentException(ExceptionMessages.StringTooLong, paramName);
}
[DoesNotReturn]
public static void ThrowStringTooLongException(string paramName)
{
throw StringTooLongException(paramName);
}
public static ArgumentOutOfRangeException ZeroThroughOneException(string paramName)
{
return new ArgumentOutOfRangeException(paramName, ExceptionMessages.ZeroThroughOne);
}
[DoesNotReturn]
public static void ThrowZeroThroughOneException(string paramName)
{
throw ZeroThroughOneException(paramName);
}
} }

View File

@ -43,20 +43,26 @@ public sealed class InviteRequest : IEquatable<InviteRequest>
/// <value>The user which sent the request.</value> /// <value>The user which sent the request.</value>
public VirtualParadiseUser User { get; } public VirtualParadiseUser User { get; }
/// <inheritdoc /> /// <summary>
public bool Equals(InviteRequest? other) /// Returns a value indicating whether two <see cref="InviteRequest" /> instances are equal.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns><see langword="true" /> if the two instances are equal; otherwise, <see langword="false" />.</returns>
public static bool operator ==(InviteRequest? left, InviteRequest? right)
{ {
if (ReferenceEquals(null, other)) return Equals(left, right);
{
return false;
} }
if (ReferenceEquals(this, other)) /// <summary>
/// Returns a value indicating whether two <see cref="InviteRequest" /> instances are not equal.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns><see langword="true" /> if the two instances are not equal; otherwise, <see langword="false" />.</returns>
public static bool operator !=(InviteRequest? left, InviteRequest? right)
{ {
return true; return !Equals(left, right);
}
return _requestId == other._requestId && _client.Equals(other._client);
} }
/// <summary> /// <summary>
@ -93,6 +99,22 @@ public sealed class InviteRequest : IEquatable<InviteRequest>
return Task.CompletedTask; return Task.CompletedTask;
} }
/// <inheritdoc />
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);
}
/// <inheritdoc /> /// <inheritdoc />
public override bool Equals(object? obj) public override bool Equals(object? obj)
{ {
@ -105,9 +127,8 @@ public sealed class InviteRequest : IEquatable<InviteRequest>
} }
/// <inheritdoc /> /// <inheritdoc />
public override int GetHashCode() => HashCode.Combine(_client, _requestId); public override int GetHashCode()
{
public static bool operator ==(InviteRequest left, InviteRequest right) => Equals(left, right); return HashCode.Combine(_client, _requestId);
}
public static bool operator !=(InviteRequest left, InviteRequest right) => !Equals(left, right);
} }

View File

@ -1,4 +1,4 @@
using VpSharp.Entities; using VpSharp.Entities;
using VpSharp.Extensions; using VpSharp.Extensions;
using VpSharp.Internal; using VpSharp.Internal;
@ -32,9 +32,27 @@ public sealed class JoinRequest : IEquatable<JoinRequest>
/// <value>The user which sent the request.</value> /// <value>The user which sent the request.</value>
public VirtualParadiseUser User { get; } public VirtualParadiseUser User { get; }
public static bool operator ==(JoinRequest left, JoinRequest right) => Equals(left, right); /// <summary>
/// Returns a value indicating whether two <see cref="JoinRequest" /> instances are equal.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns><see langword="true" /> if the two instances are equal; otherwise, <see langword="false" />.</returns>
public static bool operator ==(JoinRequest? left, JoinRequest? right)
{
return Equals(left, right);
}
public static bool operator !=(JoinRequest left, JoinRequest right) => !Equals(left, right); /// <summary>
/// Returns a value indicating whether two <see cref="JoinRequest" /> instances are not equal.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns><see langword="true" /> if the two instances are not equal; otherwise, <see langword="false" />.</returns>
public static bool operator !=(JoinRequest? left, JoinRequest? right)
{
return !Equals(left, right);
}
/// <summary> /// <summary>
/// Accepts this join request. /// Accepts this join request.
@ -75,7 +93,6 @@ public sealed class JoinRequest : IEquatable<JoinRequest>
return Task.CompletedTask; return Task.CompletedTask;
} }
/// <inheritdoc /> /// <inheritdoc />
public bool Equals(JoinRequest? other) public bool Equals(JoinRequest? other)
{ {
@ -104,5 +121,8 @@ public sealed class JoinRequest : IEquatable<JoinRequest>
} }
/// <inheritdoc /> /// <inheritdoc />
public override int GetHashCode() => HashCode.Combine(_client, _requestId); public override int GetHashCode()
{
return HashCode.Combine(_client, _requestId);
}
} }

View File

@ -79,14 +79,20 @@ public struct Vector3d : IEquatable<Vector3d>, IFormattable
/// </summary> /// </summary>
/// <value>The length of the vector.</value> /// <value>The length of the vector.</value>
/// <seealso cref="LengthSquared" /> /// <seealso cref="LengthSquared" />
public double Length => Distance(this, Zero); public double Length
{
get => Distance(this, Zero);
}
/// <summary> /// <summary>
/// Gets the squared length of the vector. /// Gets the squared length of the vector.
/// </summary> /// </summary>
/// <value>The length of the vector, squared.</value> /// <value>The length of the vector, squared.</value>
/// <seealso cref="Length" /> /// <seealso cref="Length" />
public double LengthSquared => DistanceSquared(this, Zero); public double LengthSquared
{
get => DistanceSquared(this, Zero);
}
/// <summary> /// <summary>
/// Gets or sets the X component of the vector. /// Gets or sets the X component of the vector.
@ -227,7 +233,10 @@ public struct Vector3d : IEquatable<Vector3d>, IFormattable
/// <param name="left">The first vector to compare.</param> /// <param name="left">The first vector to compare.</param>
/// <param name="right">The second vector to compare.</param> /// <param name="right">The second vector to compare.</param>
/// <returns><see langword="true" /> if the two vectors are equal; otherwise, <see langword="false" />.</returns> /// <returns><see langword="true" /> if the two vectors are equal; otherwise, <see langword="false" />.</returns>
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);
}
/// <summary> /// <summary>
/// Returns a value indicating whether the two given vectors are not equal. /// Returns a value indicating whether the two given vectors are not equal.
@ -235,7 +244,10 @@ public struct Vector3d : IEquatable<Vector3d>, IFormattable
/// <param name="left">The first vector to compare.</param> /// <param name="left">The first vector to compare.</param>
/// <param name="right">The second vector to compare.</param> /// <param name="right">The second vector to compare.</param>
/// <returns><see langword="true" /> if the two vectors are not equal; otherwise, <see langword="false" />.</returns> /// <returns><see langword="true" /> if the two vectors are not equal; otherwise, <see langword="false" />.</returns>
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);
}
/// <summary> /// <summary>
/// Implicitly converts a <see cref="Vector3" /> to a new instance of <see cref="Vector3d" />, by implicitly converting /// Implicitly converts a <see cref="Vector3" /> to a new instance of <see cref="Vector3d" />, by implicitly converting
@ -482,13 +494,22 @@ public struct Vector3d : IEquatable<Vector3d>, IFormattable
/// </summary> /// </summary>
/// <param name="other">The vector to compare with this instance.</param> /// <param name="other">The vector to compare with this instance.</param>
/// <returns><see langword="true" /> if the two vectors are equal; otherwise, <see langword="false" />.</returns> /// <returns><see langword="true" /> if the two vectors are equal; otherwise, <see langword="false" />.</returns>
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);
}
/// <inheritdoc /> /// <inheritdoc />
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);
}
/// <inheritdoc /> /// <inheritdoc />
public override readonly int GetHashCode() => HashCode.Combine(X, Y, Z); public override readonly int GetHashCode()
{
return HashCode.Combine(X, Y, Z);
}
/// <summary> /// <summary>
/// Returns a <see cref="string" /> representing this <see cref="Vector3d" /> instance. /// Returns a <see cref="string" /> representing this <see cref="Vector3d" /> instance.