Implemented IEquatable for several classes.

This commit is contained in:
mmuffins 2018-05-31 16:49:01 +02:00
parent 8f4d29bca7
commit 254d2e2516
5 changed files with 153 additions and 8 deletions

View File

@ -10,7 +10,7 @@ using Newtonsoft.Json.Linq;
namespace SteamStorefrontAPI.Classes
{
public class SteamApp
public class SteamApp : IEquatable<SteamApp>
{
[JsonProperty("type")]
public string Type { get; set; }
@ -128,7 +128,8 @@ namespace SteamStorefrontAPI.Classes
this.DLC = new List<int>();
}
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<SteamApp>(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();
}
}
}

View File

@ -11,7 +11,7 @@ namespace SteamStorefrontAPI.Classes
{
public enum ControllerSupport { Full, Partial };
public class AppInfo
public class AppInfo : IEquatable<AppInfo>
{
[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();
}
}
}

View File

@ -9,7 +9,7 @@ using Newtonsoft.Json.Converters;
namespace SteamStorefrontAPI.Classes
{
public class PriceOverview
public class PriceOverview : IEquatable<PriceOverview>
{
[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();
}
}
}

View File

@ -9,7 +9,7 @@ using Newtonsoft.Json.Converters;
namespace SteamStorefrontAPI.Classes
{
public class FeaturedCategory
public class FeaturedCategory : IEquatable<FeaturedCategory>
{
[JsonProperty("id")]
public string Id { get; set; }
@ -47,7 +47,33 @@ namespace SteamStorefrontAPI.Classes
return JsonConvert.DeserializeObject<FeaturedCategory>(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();
}
}
}

View File

@ -9,12 +9,40 @@ using Newtonsoft.Json.Converters;
namespace SteamStorefrontAPI.Classes
{
public partial class PackageApp
public partial class PackageApp : IEquatable<PackageApp>
{
[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();
}
}
}