BadScript 2
Loading...
Searching...
No Matches
ParserResultExtensionsAsync.cs
Go to the documentation of this file.
1// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
2
3using System;
4using System.Collections.Generic;
5using System.Threading.Tasks;
6
7namespace CommandLine
8{
9 public static partial class ParserResultExtensions
10 {
11#if !NET40
20 public static async Task<ParserResult<T>> WithParsedAsync<T>(this ParserResult<T> result, Func<T, Task> action)
21 {
22 if (result is Parsed<T> parsed)
23 {
24 await action(parsed.Value);
25 }
26
27 return result;
28 }
29
37 public static async Task<ParserResult<object>> WithParsedAsync<T>(
38 this ParserResult<object> result,
39 Func<T, Task> action)
40 {
41 if (result is Parsed<object> parsed)
42 {
43 if (parsed.Value is T value)
44 {
45 await action(value);
46 }
47 }
48
49 return result;
50 }
51
60 public static async Task<ParserResult<T>> WithNotParsedAsync<T>(this ParserResult<T> result,
61 Func<IEnumerable<Error>, Task> action)
62 {
63 if (result is NotParsed<T> notParsed)
64 {
65 await action(notParsed.Errors);
66 }
67
68 return result;
69 }
70#endif
71 }
72}
It contains a sequence of CommandLine.Error.
It contains an instance of type T with parsed values.
static async Task< ParserResult< T > > WithNotParsedAsync< T >(this ParserResult< T > result, Func< IEnumerable< Error >, Task > action)
Executes asynchronously action if CommandLine.ParserResult<T> lacks parsed values and contains error...
static async Task< ParserResult< T > > WithParsedAsync< T >(this ParserResult< T > result, Func< T, Task > action)
Executes asynchronously action if CommandLine.ParserResult<T> contains parsed values.
Models a parser result. When inherited by CommandLine.Parsed<T>, it contains an instance of type T w...