-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from Atlas-Rhythm/fix/link-serialization
Fixed and improved link serialization
- Loading branch information
Showing
9 changed files
with
80 additions
and
12 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
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
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
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
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,60 @@ | ||
using System; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Hive.Models; | ||
|
||
/// <summary> | ||
/// Represented a named link, something with a readable identifier and a Uri location | ||
/// </summary> | ||
public readonly struct Link : IEquatable<Link> | ||
{ | ||
/// <summary> | ||
/// The name of the link. | ||
/// </summary> | ||
public string Name { get; } = string.Empty; | ||
|
||
/// <summary> | ||
/// The location (uRI) of the link. | ||
/// </summary> | ||
public Uri Location { get; } = null!; | ||
|
||
/// <summary> | ||
/// Construct a Link object with a name and Uri | ||
/// </summary> | ||
/// <param name="name"></param> | ||
/// <param name="location"></param> | ||
[JsonConstructor] | ||
public Link(string name, Uri location) | ||
{ | ||
Name = name; | ||
Location = location; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override string ToString() => $"({Name})[{Location}]"; | ||
|
||
/// <inheritdoc/> | ||
public bool Equals(Link other) => Name == other.Name && Location.Equals(other.Location); | ||
|
||
/// <inheritdoc/> | ||
public override bool Equals(object? obj) => obj is Link other && Equals(other); | ||
|
||
/// <inheritdoc/> | ||
public override int GetHashCode() => HashCode.Combine(Name, Location); | ||
|
||
/// <summary> | ||
/// Equals operator | ||
/// </summary> | ||
/// <param name="left"></param> | ||
/// <param name="right"></param> | ||
/// <returns></returns> | ||
public static bool operator ==(Link left, Link right) => left.Equals(right); | ||
|
||
/// <summary> | ||
/// Not equals operator | ||
/// </summary> | ||
/// <param name="left"></param> | ||
/// <param name="right"></param> | ||
/// <returns></returns> | ||
public static bool operator !=(Link left, Link right) => !left.Equals(right); | ||
} |
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
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
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
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