summaryrefslogtreecommitdiff
path: root/src/SMAPI.Toolkit/Framework/UpdateData/UpdateKey.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-07-29 16:43:25 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-09-14 18:59:29 -0400
commit1d085df5b796e02b3e9e6874bd4e5684e840cb92 (patch)
tree9c0bb39b7bc6e4618ed2bad4ca17af6f82b1a737 /src/SMAPI.Toolkit/Framework/UpdateData/UpdateKey.cs
parent2b4bc2c282e17ba431f9a6ec1892b87a37eb4bb7 (diff)
downloadSMAPI-1d085df5b796e02b3e9e6874bd4e5684e840cb92.tar.gz
SMAPI-1d085df5b796e02b3e9e6874bd4e5684e840cb92.tar.bz2
SMAPI-1d085df5b796e02b3e9e6874bd4e5684e840cb92.zip
track license info for mod GitHub repos (#651)
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();
+ }
}
}