From 47dbc4ab57b7f3f8c69b00eb8fef113edb517e01 Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Tue, 8 Mar 2022 20:06:54 +0000 Subject: [PATCH] (#2630) Remove properties from ConfigFileSettings These properties had previously been marked as Obsolete, and since we are releasing the 1.0.0 version of Chocolatey, the decision has been taken to remove these properties completely. There were some usages of these properties, in the Equals and GetHashCode methods for the class, but their removal isn't believed to cause any issues. A new OfEach method was added to the HashCode class to handle the scenario where the first property passed in to generate the overall hashcode for the class was of type IEnumerable. --- .../configuration/ConfigFileSettings.cs | 16 ++-------------- .../infrastructure.app/utility/HashCode.cs | 11 +++++++++++ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/chocolatey/infrastructure.app/configuration/ConfigFileSettings.cs b/src/chocolatey/infrastructure.app/configuration/ConfigFileSettings.cs index 6a27d40a35..26636918c6 100644 --- a/src/chocolatey/infrastructure.app/configuration/ConfigFileSettings.cs +++ b/src/chocolatey/infrastructure.app/configuration/ConfigFileSettings.cs @@ -27,14 +27,6 @@ namespace chocolatey.infrastructure.app.configuration [XmlRoot("chocolatey")] public class ConfigFileSettings { - [Obsolete("This will be removed in v1 of Chocolatey")] - [XmlElement(ElementName = "cacheLocation")] - public string CacheLocation { get; set; } - - [Obsolete("This will be removed in v1 of Chocolatey")] - [XmlElement(ElementName = "commandExecutionTimeoutSeconds")] - public int CommandExecutionTimeoutSeconds { get; set; } - [XmlArray("config")] public HashSet ConfigSettings { get; set; } @@ -57,9 +49,7 @@ public override bool Equals(object obj) var item = (ConfigFileSettings) obj; - return (CacheLocation == item.CacheLocation) - && (CommandExecutionTimeoutSeconds == item.CommandExecutionTimeoutSeconds) - && (ConfigSettings == item.ConfigSettings) + return (ConfigSettings == item.ConfigSettings) && (Sources == item.Sources) && (Features == item.Features) && (ApiKeys == item.ApiKeys); @@ -68,9 +58,7 @@ public override bool Equals(object obj) public override int GetHashCode() { return HashCode - .Of(CacheLocation) - .And(CommandExecutionTimeoutSeconds) - .AndEach(ConfigSettings) + .OfEach(ConfigSettings) .AndEach(Sources) .AndEach(Features) .AndEach(ApiKeys); diff --git a/src/chocolatey/infrastructure.app/utility/HashCode.cs b/src/chocolatey/infrastructure.app/utility/HashCode.cs index cac40983e2..21522be0fb 100644 --- a/src/chocolatey/infrastructure.app/utility/HashCode.cs +++ b/src/chocolatey/infrastructure.app/utility/HashCode.cs @@ -43,6 +43,17 @@ public static HashCode Of(T item) return new HashCode(GetHashCode(item)); } + public static HashCode OfEach(IEnumerable items) + { + if (items == null) + { + return new HashCode(this.value); + } + + var hashCode = items.Any() ? items.Select(GetHashCode).Aggregate(CombineHashCodes) : 0; + return new HashCode(CombineHashCodes(this.value, hashCode)); + } + public HashCode And(T item) { return new HashCode(CombineHashCodes(this.value, GetHashCode(item)));