/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/standard/commandline/snippets/model-binding/csharp/ContextExitCode.cs
32 строки
1 KB
Tom Dykstra
System.CommandLine beta 4 (#29580)
02 июн 2022, 20:36
Не верифицирован
02 июн 2022, 20:36
375b2c5
Код
Авторство
О чём код?
using System.CommandLine; using System.CommandLine.Invocation; namespace ContextExitCode; class Program { // <contextexitcode> static async Task<int> Main(string[] args) { var delayOption = new Option<int>("--delay"); var messageOption = new Option<string>("--message"); var rootCommand = new RootCommand("Parameter binding example"); rootCommand.Add(delayOption); rootCommand.Add(messageOption); rootCommand.SetHandler(async (context) => { int delayOptionValue = context.ParseResult.GetValueForOption(delayOption); string? messageOptionValue = context.ParseResult.GetValueForOption(messageOption); Console.WriteLine($"--delay = {delayOptionValue}"); await Task.Delay(delayOptionValue); Console.WriteLine($"--message = {messageOptionValue}"); context.ExitCode = 100; }); return await rootCommand.InvokeAsync(args); } // </contextexitcode> }