Skip to content

Commit 12089c3

Browse files
committed
fix(tooling): non-existent collection in property delegates
1 parent f301f01 commit 12089c3

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

source/Nuke.Common.Tests/SettingsTest.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,28 @@ public void TestDotNet()
126126
"pack --property:Authors=a,b");
127127
}
128128

129+
[Fact]
130+
public void TestDotNet_Delegate()
131+
{
132+
Assert(new DotNetBuildSettings()
133+
.SetNoWarns(1337),
134+
"build --property:NoWarn=1337");
135+
136+
Assert(new DotNetBuildSettings()
137+
.SetNoWarns(1337, 555)
138+
.RemoveNoWarns(555),
139+
"build --property:NoWarn=1337");
140+
141+
Assert(new DotNetBuildSettings()
142+
.AddNoWarns(1337),
143+
"build --property:NoWarn=1337");
144+
145+
Assert(new DotNetBuildSettings()
146+
.AddNoWarns(1337)
147+
.SetNoWarns(555),
148+
"build --property:NoWarn=555");
149+
}
150+
129151
[Fact]
130152
public void TestDotNet_Empty()
131153
{

source/Nuke.Tooling/DelegateHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ public static IDictionary<string, object> RemoveCollection<TValue>(
5555
var newDictionary = dictionary?.ToDictionary(x => x.Key, x => x.Value) ?? new Dictionary<string, object>();
5656
var valueHashSet = new HashSet<TValue>(values);
5757
var collection = ParseCollection<TValue>(dictionary, key, separator);
58-
collection.RemoveAll(x => valueHashSet.Contains((TValue)x));
58+
collection.RemoveAll(x => valueHashSet.Contains(x));
5959
newDictionary[key] = CollectionToString(collection, separator);
6060
return newDictionary;
6161
}
6262

6363
private static List<TValue> ParseCollection<TValue>(IReadOnlyDictionary<string, object> dictionary, string key, string separator)
6464
{
65-
return (dictionary.TryGetValue(key, out var value)
65+
return (dictionary?.TryGetValue(key, out var value) ?? false
6666
? ((string)value).Split([separator], StringSplitOptions.RemoveEmptyEntries)
6767
: [])
6868
.Select(ReflectionUtility.Convert<TValue>).ToList();

0 commit comments

Comments
 (0)