Skip to content

Commit

Permalink
complex args doc
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Sep 17, 2019
1 parent beb4583 commit f871920
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
27 changes: 27 additions & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,33 @@ also use with `help`
-msg: String
```

Complex Argument
---
If the argument is not primitive, you can pass JSON string.

```csharp
public class ComplexArgTest : BatchBase
{
public void Foo(int[] array, Person person)
{
Console.WriteLine(string.Join(", ", array));
Console.WriteLine(person.Age + ":" + person.Name);
}
}

public class Person
{
public int Age { get; set; }
public string Name { get; set; }
}
```

You can call like here.

```
> SampleApp.exe -array [10,20,30] -person {"Age":10,"Name":"foo"}
```

Daemon
---

Expand Down
19 changes: 18 additions & 1 deletion sandbox/SingleContainedApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,34 @@ public void Help()
}
}

public class ComplexArgTest : BatchBase
{
public void Foo(int[] array, Person person)
{
Console.WriteLine(string.Join(", ", array));
Console.WriteLine(person.Age + ":" + person.Name);
}
}

public class Person
{
public int Age { get; set; }
public string Name { get; set; }
}

class Program
{
static async Task Main(string[] args)
{
args = @"-array [10,20,30] -person {""Age"":10,""Name"":""foo""}".Split(' ');

await BatchHost.CreateDefaultBuilder()
.ConfigureServices((hostContext, services) =>
{
// mapping config json to IOption<MyConfig>
services.Configure<MyConfig>(hostContext.Configuration);
})
.RunBatchEngineAsync<MyFirstBatch>(args);
.RunBatchEngineAsync<ComplexArgTest>(args);
}
}
}

0 comments on commit f871920

Please sign in to comment.