-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0686b04
commit 4deb566
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Text.Json.Serialization; | ||
|
||
using Weatherstack.Annotations.Suppression; | ||
|
||
namespace Weatherstack; | ||
|
||
/// <summary> | ||
/// Represents a coordinate in the world. | ||
/// </summary> | ||
public struct WorldCoordinate | ||
: IEquatable<WorldCoordinate> | ||
{ | ||
/// <summary> | ||
/// Gets or sets the latitude of the coordinate. | ||
/// </summary> | ||
[JsonPropertyName("lat")] | ||
public double Latitude { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the longitude of the coordinate. | ||
/// </summary> | ||
[JsonPropertyName("lon")] | ||
public double Longitude { get; set; } | ||
|
||
/// <inheritdoc/> | ||
[SuppressMessage( | ||
category: "Style", | ||
checkId: "IDE0046", | ||
Justification = Justifications.GuardClausesShouldNotBeTerse)] | ||
public override bool Equals(object obj) | ||
Check failure on line 31 in src/Weatherstack/WorldCoordinate.cs
|
||
{ | ||
if (obj is not WorldCoordinate other) | ||
return false; | ||
|
||
return Equals(other); | ||
} | ||
|
||
public bool Equals(WorldCoordinate other) => Latitude == other.Latitude | ||
&& Longitude == other.Longitude; | ||
|
||
/// <inheritdoc/> | ||
public override int GetHashCode() | ||
{ | ||
#if NET6_0_OR_GREATER | ||
|
||
return HashCode.Combine(Latitude, Longitude); | ||
|
||
#else | ||
|
||
return 17 | ||
* 23 + Latitude.GetHashCode() | ||
* 23 + Longitude.GetHashCode(); | ||
|
||
#endif | ||
} | ||
|
||
public static bool operator ==(WorldCoordinate left, WorldCoordinate right) => | ||
left.Equals(right); | ||
|
||
public static bool operator !=(WorldCoordinate left, WorldCoordinate right) => | ||
!left.Equals(right); | ||
} |