From 254d2e251604421da8535be71a5f910908f71a64 Mon Sep 17 00:00:00 2001 From: mmuffins Date: Thu, 31 May 2018 16:49:01 +0200 Subject: [PATCH] Implemented IEquatable for several classes. --- .../Classes/appdetails/SteamApp.cs | 33 +++++++++++++++-- SteamStorefrontAPI/Classes/common/AppInfo.cs | 30 +++++++++++++++- .../Classes/common/PriceOverview.cs | 36 ++++++++++++++++++- .../featuredcategories/FeaturedCategory.cs | 32 +++++++++++++++-- .../Classes/packagedetails/PackageApp.cs | 30 +++++++++++++++- 5 files changed, 153 insertions(+), 8 deletions(-) diff --git a/SteamStorefrontAPI/Classes/appdetails/SteamApp.cs b/SteamStorefrontAPI/Classes/appdetails/SteamApp.cs index 0a3d415..e850b58 100644 --- a/SteamStorefrontAPI/Classes/appdetails/SteamApp.cs +++ b/SteamStorefrontAPI/Classes/appdetails/SteamApp.cs @@ -10,7 +10,7 @@ using Newtonsoft.Json.Linq; namespace SteamStorefrontAPI.Classes { - public class SteamApp + public class SteamApp : IEquatable { [JsonProperty("type")] public string Type { get; set; } @@ -128,7 +128,8 @@ namespace SteamStorefrontAPI.Classes this.DLC = new List(); } - public static SteamApp FromJson(string json) { + public static SteamApp FromJson(string json) + { var serializerSettings = new JsonSerializerSettings { @@ -141,5 +142,33 @@ namespace SteamStorefrontAPI.Classes return JsonConvert.DeserializeObject(json, serializerSettings); } + + public bool Equals(SteamApp other) + { + if (other == null) + return false; + + if (this.SteamAppId == other.SteamAppId && this.Type == other.Type) + return true; + else + return false; + } + + public override bool Equals(Object obj) + { + if (obj == null) + return false; + + SteamApp personObj = obj as SteamApp; + if (personObj == null) + return false; + else + return Equals(personObj); + } + + public override int GetHashCode() + { + return this.SteamAppId.GetHashCode(); + } } } diff --git a/SteamStorefrontAPI/Classes/common/AppInfo.cs b/SteamStorefrontAPI/Classes/common/AppInfo.cs index fab2361..7d97768 100644 --- a/SteamStorefrontAPI/Classes/common/AppInfo.cs +++ b/SteamStorefrontAPI/Classes/common/AppInfo.cs @@ -11,7 +11,7 @@ namespace SteamStorefrontAPI.Classes { public enum ControllerSupport { Full, Partial }; - public class AppInfo + public class AppInfo : IEquatable { [JsonProperty("id")] public int Id { get; set; } @@ -73,5 +73,33 @@ namespace SteamStorefrontAPI.Classes [JsonProperty("purchase_package", NullValueHandling = NullValueHandling.Ignore)] public string PurchasePackage { get; set; } + + public bool Equals(AppInfo other) + { + if (other == null) + return false; + + if (this.Id == other.Id && this.Type == other.Type) + return true; + else + return false; + } + + public override bool Equals(Object obj) + { + if (obj == null) + return false; + + AppInfo personObj = obj as AppInfo; + if (personObj == null) + return false; + else + return Equals(personObj); + } + + public override int GetHashCode() + { + return this.Id.GetHashCode(); + } } } diff --git a/SteamStorefrontAPI/Classes/common/PriceOverview.cs b/SteamStorefrontAPI/Classes/common/PriceOverview.cs index b2cca4c..932f444 100644 --- a/SteamStorefrontAPI/Classes/common/PriceOverview.cs +++ b/SteamStorefrontAPI/Classes/common/PriceOverview.cs @@ -9,7 +9,7 @@ using Newtonsoft.Json.Converters; namespace SteamStorefrontAPI.Classes { - public class PriceOverview + public class PriceOverview : IEquatable { [JsonProperty("currency")] public string Currency { get; set; } @@ -28,5 +28,39 @@ namespace SteamStorefrontAPI.Classes [JsonProperty("individual", NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(SteamPriceStringConverter))] public double Individual { get; set; } + + public bool Equals(PriceOverview other) + { + if (other == null) + return false; + + if (this.Final == other.Final + && this.Currency == other.Currency + && this.Initial == other.Initial) + { + return true; + } + + return false; + } + + public override bool Equals(Object obj) + { + if (obj == null) + return false; + + PriceOverview personObj = obj as PriceOverview; + if (personObj == null) + return false; + else + return Equals(personObj); + } + + public override int GetHashCode() + { + return this.Final.GetHashCode() + ^ this.Initial.GetHashCode() + ^ this.Currency.GetHashCode(); + } } } diff --git a/SteamStorefrontAPI/Classes/featuredcategories/FeaturedCategory.cs b/SteamStorefrontAPI/Classes/featuredcategories/FeaturedCategory.cs index ebf9211..95b6b41 100644 --- a/SteamStorefrontAPI/Classes/featuredcategories/FeaturedCategory.cs +++ b/SteamStorefrontAPI/Classes/featuredcategories/FeaturedCategory.cs @@ -9,7 +9,7 @@ using Newtonsoft.Json.Converters; namespace SteamStorefrontAPI.Classes { - public class FeaturedCategory + public class FeaturedCategory : IEquatable { [JsonProperty("id")] public string Id { get; set; } @@ -47,7 +47,33 @@ namespace SteamStorefrontAPI.Classes return JsonConvert.DeserializeObject(json, serializerSettings); } + + public bool Equals(FeaturedCategory other) + { + if (other == null) + return false; + + if (this.Id == other.Id) + return true; + else + return false; + } + + public override bool Equals(Object obj) + { + if (obj == null) + return false; + + FeaturedCategory personObj = obj as FeaturedCategory; + if (personObj == null) + return false; + else + return Equals(personObj); + } + + public override int GetHashCode() + { + return this.Id.GetHashCode(); + } } - - } diff --git a/SteamStorefrontAPI/Classes/packagedetails/PackageApp.cs b/SteamStorefrontAPI/Classes/packagedetails/PackageApp.cs index dc6cd13..0d6ac65 100644 --- a/SteamStorefrontAPI/Classes/packagedetails/PackageApp.cs +++ b/SteamStorefrontAPI/Classes/packagedetails/PackageApp.cs @@ -9,12 +9,40 @@ using Newtonsoft.Json.Converters; namespace SteamStorefrontAPI.Classes { - public partial class PackageApp + public partial class PackageApp : IEquatable { [JsonProperty("id")] public int Id { get; set; } [JsonProperty("name")] public string Name { get; set; } + + public bool Equals(PackageApp other) + { + if (other == null) + return false; + + if (this.Id == other.Id) + return true; + else + return false; + } + + public override bool Equals(Object obj) + { + if (obj == null) + return false; + + PackageApp personObj = obj as PackageApp; + if (personObj == null) + return false; + else + return Equals(personObj); + } + + public override int GetHashCode() + { + return this.Id.GetHashCode(); + } } }