summaryrefslogtreecommitdiff
path: root/src/SMAPI.Toolkit/Framework/UpdateData/UpdateKey.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-11-24 13:49:30 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-11-24 13:49:30 -0500
commita3f21685049cabf2d824c8060dc0b1de47e9449e (patch)
treead9add30e9da2a50e0ea0245f1546b7378f0d282 /src/SMAPI.Toolkit/Framework/UpdateData/UpdateKey.cs
parent6521df7b131924835eb797251c1e956fae0d6e13 (diff)
parent277bf082675b98b95bf6184fe3c7a45b969c7ac2 (diff)
downloadSMAPI-a3f21685049cabf2d824c8060dc0b1de47e9449e.tar.gz
SMAPI-a3f21685049cabf2d824c8060dc0b1de47e9449e.tar.bz2
SMAPI-a3f21685049cabf2d824c8060dc0b1de47e9449e.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI.Toolkit/Framework/UpdateData/UpdateKey.cs')
-rw-r--r--src/SMAPI.Toolkit/Framework/UpdateData/UpdateKey.cs32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/SMAPI.Toolkit/Framework/UpdateData/UpdateKey.cs b/src/SMAPI.Toolkit/Framework/UpdateData/UpdateKey.cs
index 865ebcf7..3fc1759e 100644
--- a/src/SMAPI.Toolkit/Framework/UpdateData/UpdateKey.cs
+++ b/src/SMAPI.Toolkit/Framework/UpdateData/UpdateKey.cs
@@ -3,7 +3,7 @@ using System;
namespace StardewModdingAPI.Toolkit.Framework.UpdateData
{
/// <summary>A namespaced mod ID which uniquely identifies a mod within a mod repository.</summary>
- public class UpdateKey
+ public class UpdateKey : IEquatable<UpdateKey>
{
/*********
** Accessors
@@ -38,6 +38,12 @@ namespace StardewModdingAPI.Toolkit.Framework.UpdateData
&& !string.IsNullOrWhiteSpace(id);
}
+ /// <summary>Construct an instance.</summary>
+ /// <param name="repository">The mod repository containing the mod.</param>
+ /// <param name="id">The mod ID within the repository.</param>
+ public UpdateKey(ModRepositoryKey repository, string id)
+ : this($"{repository}:{id}", repository, id) { }
+
/// <summary>Parse a raw update key.</summary>
/// <param name="raw">The raw update key to parse.</param>
public static UpdateKey Parse(string raw)
@@ -69,5 +75,29 @@ namespace StardewModdingAPI.Toolkit.Framework.UpdateData
? $"{this.Repository}:{this.ID}"
: this.RawText;
}
+
+ /// <summary>Indicates whether the current object is equal to another object of the same type.</summary>
+ /// <param name="other">An object to compare with this object.</param>
+ public bool Equals(UpdateKey other)
+ {
+ return
+ other != null
+ && this.Repository == other.Repository
+ && string.Equals(this.ID, other.ID, StringComparison.InvariantCultureIgnoreCase);
+ }
+
+ /// <summary>Determines whether the specified object is equal to the current object.</summary>
+ /// <param name="obj">The object to compare with the current object.</param>
+ public override bool Equals(object obj)
+ {
+ return obj is UpdateKey other && this.Equals(other);
+ }
+
+ /// <summary>Serves as the default hash function. </summary>
+ /// <returns>A hash code for the current object.</returns>
+ public override int GetHashCode()
+ {
+ return $"{this.Repository}:{this.ID}".ToLower().GetHashCode();
+ }
}
}