mirror of
https://github.com/oliverbooth/VpSharp
synced 2024-11-10 02:55:41 +00:00
Use statement bodies
This commit is contained in:
parent
99c08f33ed
commit
b4deeaf92c
@ -38,7 +38,10 @@ public readonly struct Cell : IEquatable<Cell>, IFormattable
|
||||
/// <param name="left">The first 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>
|
||||
public static bool operator ==(Cell left, Cell right) => left.Equals(right);
|
||||
public static bool operator ==(Cell left, Cell right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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="right">The second cell to compare.</param>
|
||||
/// <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>
|
||||
/// 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>
|
||||
/// <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>
|
||||
public bool Equals(Cell other) => X == other.X && Z == other.Z;
|
||||
public bool Equals(Cell other)
|
||||
{
|
||||
return X == other.X && Z == other.Z;
|
||||
}
|
||||
|
||||
/// <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 />
|
||||
public override int GetHashCode() => HashCode.Combine(X, Z);
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(X, Z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="string" /> representing this <see cref="Vector3d" /> instance.
|
||||
|
@ -30,7 +30,10 @@ public sealed class VirtualParadiseAvatar : IEquatable<VirtualParadiseAvatar>
|
||||
/// Gets a value indicating whether this avatar is a bot.
|
||||
/// </summary>
|
||||
/// <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>
|
||||
/// Gets the location of this avatar.
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -43,20 +43,26 @@ public sealed class InviteRequest : IEquatable<InviteRequest>
|
||||
/// <value>The user which sent the request.</value>
|
||||
public VirtualParadiseUser User { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Equals(InviteRequest? other)
|
||||
/// <summary>
|
||||
/// 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 false;
|
||||
}
|
||||
return Equals(left, right);
|
||||
}
|
||||
|
||||
if (ReferenceEquals(this, other))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return _requestId == other._requestId && _client.Equals(other._client);
|
||||
/// <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 !Equals(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -93,6 +99,22 @@ public sealed class InviteRequest : IEquatable<InviteRequest>
|
||||
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 />
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
@ -105,9 +127,8 @@ public sealed class InviteRequest : IEquatable<InviteRequest>
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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<JoinRequest>
|
||||
/// <value>The user which sent the request.</value>
|
||||
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>
|
||||
/// Accepts this join request.
|
||||
@ -75,7 +93,6 @@ public sealed class JoinRequest : IEquatable<JoinRequest>
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Equals(JoinRequest? other)
|
||||
{
|
||||
@ -104,5 +121,8 @@ public sealed class JoinRequest : IEquatable<JoinRequest>
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int GetHashCode() => HashCode.Combine(_client, _requestId);
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(_client, _requestId);
|
||||
}
|
||||
}
|
||||
|
@ -79,14 +79,20 @@ public struct Vector3d : IEquatable<Vector3d>, IFormattable
|
||||
/// </summary>
|
||||
/// <value>The length of the vector.</value>
|
||||
/// <seealso cref="LengthSquared" />
|
||||
public double Length => Distance(this, Zero);
|
||||
public double Length
|
||||
{
|
||||
get => Distance(this, Zero);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the squared length of the vector.
|
||||
/// </summary>
|
||||
/// <value>The length of the vector, squared.</value>
|
||||
/// <seealso cref="Length" />
|
||||
public double LengthSquared => DistanceSquared(this, Zero);
|
||||
public double LengthSquared
|
||||
{
|
||||
get => DistanceSquared(this, Zero);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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="right">The second vector to compare.</param>
|
||||
/// <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>
|
||||
/// 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="right">The second vector to compare.</param>
|
||||
/// <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>
|
||||
/// 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>
|
||||
/// <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>
|
||||
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 />
|
||||
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 />
|
||||
public override readonly int GetHashCode() => HashCode.Combine(X, Y, Z);
|
||||
public override readonly int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(X, Y, Z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="string" /> representing this <see cref="Vector3d" /> instance.
|
||||
|
Loading…
Reference in New Issue
Block a user