Skip to content

Commit 22a073b

Browse files
committed
support Dictionary parameter,fix #58
1 parent c784d76 commit 22a073b

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

sandbox/SingleContainedApp/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,10 @@ public void Hello(
240240
if (hello == null) hello = DateTime.Now;
241241
Console.WriteLine(hello);
242242
}
243-
public void Dispose()
243+
244+
void IDisposable.Dispose()
244245
{
245-
Console.WriteLine("DISPOSE!");
246+
throw new NotImplementedException();
246247
}
247-
248248
}
249249
}

src/ConsoleAppFramework/ConsoleAppEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ bool TryGetInvokeArguments(ParameterInfo[] parameters, string?[] args, int argsO
271271
return false;
272272
}
273273
}
274-
else if (typeof(System.Collections.IEnumerable).IsAssignableFrom(parameters[i].ParameterType))
274+
else if (typeof(System.Collections.IEnumerable).IsAssignableFrom(parameters[i].ParameterType) && !typeof(System.Collections.IDictionary).IsAssignableFrom(parameters[i].ParameterType))
275275
{
276276
var v = value.Value;
277277
if (!(v.StartsWith("[") && v.EndsWith("]")))
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using FluentAssertions;
2+
using Microsoft.Extensions.Hosting;
3+
using Microsoft.Extensions.Logging;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Threading.Tasks;
7+
using Xunit;
8+
using Xunit.Abstractions;
9+
10+
namespace ConsoleAppFramework.Tests
11+
{
12+
public class ParameterCheckTest
13+
{
14+
ITestOutputHelper testOutput;
15+
16+
public ParameterCheckTest(ITestOutputHelper testOutput)
17+
{
18+
this.testOutput = testOutput;
19+
}
20+
21+
public class DictionaryCheck : ConsoleAppBase
22+
{
23+
public void Hello(Dictionary<string, string> q)
24+
{
25+
26+
foreach (var item in q)
27+
{
28+
Context.Logger.LogInformation($"{item.Key}:{item.Value}");
29+
}
30+
}
31+
}
32+
33+
[Fact]
34+
public async Task DictParse()
35+
{
36+
var args = @"-q {""Key1"":""Value1*""}".Split(' ');
37+
38+
var log = new LogStack();
39+
await new HostBuilder()
40+
.ConfigureTestLogging(testOutput, log, true)
41+
.RunConsoleAppFrameworkAsync<DictionaryCheck>(args);
42+
43+
log.InfoLogShouldBe(0, "Key1:Value1*");
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)