From 7bb24d8193e2ce98acfc7b3e686810483b1e7c61 Mon Sep 17 00:00:00 2001 From: Shane Gill Date: Tue, 20 Sep 2022 15:15:25 +1000 Subject: [PATCH 1/3] DONOTMERGE: Allow parameters with the same keys --- .nuke/build.schema.json | 4 ---- source/Nevermore/CommandParameterValues.cs | 2 -- 2 files changed, 6 deletions(-) diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json index 0e749245..34b5276d 100644 --- a/.nuke/build.schema.json +++ b/.nuke/build.schema.json @@ -86,10 +86,6 @@ ] } }, - "Solution": { - "type": "string", - "description": "Path to a solution file that is automatically loaded" - }, "Target": { "type": "array", "description": "List of targets to be invoked. Default is '{default_target}'", diff --git a/source/Nevermore/CommandParameterValues.cs b/source/Nevermore/CommandParameterValues.cs index e6600017..71ba1823 100644 --- a/source/Nevermore/CommandParameterValues.cs +++ b/source/Nevermore/CommandParameterValues.cs @@ -227,8 +227,6 @@ public void AddRange(CommandParameterValues other) { foreach (var item in other) { - if (ContainsKey(item.Key)) - throw new Exception($"The parameter {item.Key} already exists"); this[item.Key] = item.Value; } } From 2f5197c57827bd91e5b7e74f4db1fc0ea480a6b8 Mon Sep 17 00:00:00 2001 From: Shane Gill Date: Wed, 28 Sep 2022 11:28:29 +1000 Subject: [PATCH 2/3] Check values are the same --- source/Nevermore/CommandParameterValues.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/source/Nevermore/CommandParameterValues.cs b/source/Nevermore/CommandParameterValues.cs index 71ba1823..1c8a4b3b 100644 --- a/source/Nevermore/CommandParameterValues.cs +++ b/source/Nevermore/CommandParameterValues.cs @@ -227,6 +227,15 @@ public void AddRange(CommandParameterValues other) { foreach (var item in other) { + if (ContainsKey(item.Key)) + { + var existing = this[item.Key]; + if (!item.Value.Equals(existing)) + { + throw new Exception($"The parameter {item.Key} already exists and has a different value"); + } + } + this[item.Key] = item.Value; } } From defcd53f46dbef259681a5f976805db377f23edd Mon Sep 17 00:00:00 2001 From: Shane Gill Date: Wed, 28 Sep 2022 12:35:34 +1000 Subject: [PATCH 3/3] Support enumerable in dupe check --- source/Nevermore/CommandParameterValues.cs | 33 ++++++++++++++++------ 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/source/Nevermore/CommandParameterValues.cs b/source/Nevermore/CommandParameterValues.cs index 1c8a4b3b..860e56cc 100644 --- a/source/Nevermore/CommandParameterValues.cs +++ b/source/Nevermore/CommandParameterValues.cs @@ -227,17 +227,34 @@ public void AddRange(CommandParameterValues other) { foreach (var item in other) { - if (ContainsKey(item.Key)) + CheckForDuplicate(item); + this[item.Key] = item.Value; + } + } + + void CheckForDuplicate(KeyValuePair item) + { + if (!ContainsKey(item.Key)) + { + return; + } + var existingValue = this[item.Key]; + var newValue = item.Value; + if (existingValue.Equals(newValue)) + { + return; + } + if (existingValue is IEnumerable existingValueEnumerable && newValue is IEnumerable newValueEnumerable) + { + var existingValueSet = existingValueEnumerable.Cast().ToHashSet(); + var newValueSet = newValueEnumerable.Cast().ToHashSet(); + if (existingValueSet.SetEquals(newValueSet)) { - var existing = this[item.Key]; - if (!item.Value.Equals(existing)) - { - throw new Exception($"The parameter {item.Key} already exists and has a different value"); - } + return; } - - this[item.Key] = item.Value; } + + throw new Exception($"The parameter {item.Key} already exists and has a different value"); } } } \ No newline at end of file