From f2cb5c30be374fe51d6522d3ece678e050a24594 Mon Sep 17 00:00:00 2001 From: Claire Kuang Date: Wed, 31 Jan 2024 13:54:40 +0000 Subject: [PATCH] Update AutomateFunction.cs --- .../AutomateFunction.cs | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/SpeckleAutomateDotnetExample/AutomateFunction.cs b/SpeckleAutomateDotnetExample/AutomateFunction.cs index 7250293..8b4e7e9 100644 --- a/SpeckleAutomateDotnetExample/AutomateFunction.cs +++ b/SpeckleAutomateDotnetExample/AutomateFunction.cs @@ -118,22 +118,20 @@ static class AutomateFunction { if (releaseObjectPropDict.ContainsKey(entry.Key)) { - bool changed = false; try { - changed = entry.Value != releaseObjectPropDict[entry.Key]; - } - catch { } - if (changed) - { - string diff = - $"Property ({entry.Key}) changed from ({releaseObjectPropDict[entry.Key]}) to ({entry.Value})"; - if (!diffDictionary.ContainsKey(entry.Key)) + bool changed = !Equals(entry.Value, releaseObjectPropDict[entry.Key]); + if (changed) { - diffDictionary.Add(entry.Key, diff); + string diff = + $"Property ({entry.Key}) changed from ({releaseObjectPropDict[entry.Key]}) to ({entry.Value})"; + if (!diffDictionary.ContainsKey(entry.Key)) + { + diffDictionary.Add(entry.Key, diff); + } } } - + catch { } releaseObjectPropDict.Remove(entry.Key); } else @@ -206,4 +204,9 @@ static class AutomateFunction ); } } + + public static bool Equals(T a, T b) + { + return EqualityComparer.Default.Equals(a, b); + } }