Skip to content

Commit f871920

Browse files
committed
complex args doc
1 parent beb4583 commit f871920

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

ReadMe.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,33 @@ also use with `help`
189189
-msg: String
190190
```
191191

192+
Complex Argument
193+
---
194+
If the argument is not primitive, you can pass JSON string.
195+
196+
```csharp
197+
public class ComplexArgTest : BatchBase
198+
{
199+
public void Foo(int[] array, Person person)
200+
{
201+
Console.WriteLine(string.Join(", ", array));
202+
Console.WriteLine(person.Age + ":" + person.Name);
203+
}
204+
}
205+
206+
public class Person
207+
{
208+
public int Age { get; set; }
209+
public string Name { get; set; }
210+
}
211+
```
212+
213+
You can call like here.
214+
215+
```
216+
> SampleApp.exe -array [10,20,30] -person {"Age":10,"Name":"foo"}
217+
```
218+
192219
Daemon
193220
---
194221

sandbox/SingleContainedApp/Program.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,34 @@ public void Help()
112112
}
113113
}
114114

115+
public class ComplexArgTest : BatchBase
116+
{
117+
public void Foo(int[] array, Person person)
118+
{
119+
Console.WriteLine(string.Join(", ", array));
120+
Console.WriteLine(person.Age + ":" + person.Name);
121+
}
122+
}
123+
124+
public class Person
125+
{
126+
public int Age { get; set; }
127+
public string Name { get; set; }
128+
}
129+
115130
class Program
116131
{
117132
static async Task Main(string[] args)
118133
{
134+
args = @"-array [10,20,30] -person {""Age"":10,""Name"":""foo""}".Split(' ');
135+
119136
await BatchHost.CreateDefaultBuilder()
120137
.ConfigureServices((hostContext, services) =>
121138
{
122139
// mapping config json to IOption<MyConfig>
123140
services.Configure<MyConfig>(hostContext.Configuration);
124141
})
125-
.RunBatchEngineAsync<MyFirstBatch>(args);
142+
.RunBatchEngineAsync<ComplexArgTest>(args);
126143
}
127144
}
128145
}

0 commit comments

Comments
 (0)