From 141d4eec267a944b88f0eeb649227de06115e17e Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Wed, 27 Sep 2017 10:30:57 -0400 Subject: [PATCH] Equality comparisons for RepoConfig --- TGServerService/Repository.cs | 71 +++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 15 deletions(-) diff --git a/TGServerService/Repository.cs b/TGServerService/Repository.cs index ec6957fae7..ce11e27cc3 100644 --- a/TGServerService/Repository.cs +++ b/TGServerService/Repository.cs @@ -33,15 +33,16 @@ namespace TGServerService /// Repo specific information about the installation /// Requires RepoLock and !RepoBusy to be instantiated /// - class RepoConfig + class RepoConfig : IEquatable { - IList LoadArray(object o) { - var array = (object[])o; - var res = new List(); - foreach (var I in array) - res.Add((string)I); - return res; - } + public readonly bool ChangelogSupport; + public readonly string PathToChangelogPy; + public readonly string ChangelogPyArguments; + public readonly IList PipDependancies = new List(); + public readonly IList ChangelogPathsToStage = new List(); + public readonly IList StaticDirectoryPaths = new List(); + public readonly IList DLLPaths = new List(); + public RepoConfig() { if (!File.Exists(RepoTGS3SettingsPath)) @@ -80,13 +81,53 @@ namespace TGServerService } catch { } } - public readonly bool ChangelogSupport; - public readonly string PathToChangelogPy; - public readonly string ChangelogPyArguments; - public readonly IList PipDependancies = new List(); - public readonly IList ChangelogPathsToStage = new List(); - public readonly IList StaticDirectoryPaths = new List(); - public readonly IList DLLPaths = new List(); + private static IList LoadArray(object o) + { + var array = (object[])o; + var res = new List(); + foreach (var I in array) + res.Add((string)I); + return res; + } + + public override bool Equals(object obj) + { + return Equals(obj as RepoConfig); + } + + public bool Equals(RepoConfig other) + { + return ChangelogSupport == other.ChangelogSupport + && PathToChangelogPy == other.PathToChangelogPy + && ChangelogPyArguments == other.ChangelogPyArguments + && PipDependancies.Equals(other.PipDependancies) + && ChangelogPathsToStage.Equals(other.ChangelogPathsToStage) + && StaticDirectoryPaths.Equals(other.StaticDirectoryPaths) + && DLLPaths.Equals(other.DLLPaths); + } + + public override int GetHashCode() + { + var hashCode = 1890628544; + hashCode = hashCode * -1521134295 + ChangelogSupport.GetHashCode(); + hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(PathToChangelogPy); + hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(ChangelogPyArguments); + hashCode = hashCode * -1521134295 + EqualityComparer>.Default.GetHashCode(PipDependancies); + hashCode = hashCode * -1521134295 + EqualityComparer>.Default.GetHashCode(ChangelogPathsToStage); + hashCode = hashCode * -1521134295 + EqualityComparer>.Default.GetHashCode(StaticDirectoryPaths); + hashCode = hashCode * -1521134295 + EqualityComparer>.Default.GetHashCode(DLLPaths); + return hashCode; + } + + public static bool operator ==(RepoConfig config1, RepoConfig config2) + { + return EqualityComparer.Default.Equals(config1, config2); + } + + public static bool operator !=(RepoConfig config1, RepoConfig config2) + { + return !(config1 == config2); + } } RepoConfig _CurrentRepoConfig;