22
33using System ;
44using System . Collections . Generic ;
5- using System . Threading . Tasks ;
65
76namespace CommandLine
87{
@@ -29,24 +28,6 @@ public static ParserResult<T> WithParsed<T>(this ParserResult<T> result, Action<
2928 return result ;
3029 }
3130
32- /// <summary>
33- /// Executes asynchronously <paramref name="action"/> if <see cref="CommandLine.ParserResult{T}"/> contains
34- /// parsed values.
35- /// </summary>
36- /// <typeparam name="T">Type of the target instance built with parsed value.</typeparam>
37- /// <param name="result">An <see cref="CommandLine.ParserResult{T}"/> instance.</param>
38- /// <param name="action">The <see cref="Func{T, Task}"/> to execute.</param>
39- /// <returns>The same <paramref name="result"/> instance as a <see cref="Task"/> instance.</returns>
40- public static async Task < ParserResult < T > > WithParsedAsync < T > ( this ParserResult < T > result , Func < T , Task > action )
41- {
42- if ( result is Parsed < T > parsed )
43- {
44- await action ( parsed . Value ) ;
45- }
46- return result ;
47- }
48-
49-
5031 /// <summary>
5132 /// Executes <paramref name="action"/> if parsed values are of <typeparamref name="T"/>.
5233 /// </summary>
@@ -67,26 +48,6 @@ public static ParserResult<object> WithParsed<T>(this ParserResult<object> resul
6748 return result ;
6849 }
6950
70- /// <summary>
71- /// Executes asynchronously <paramref name="action"/> if parsed values are of <typeparamref name="T"/>.
72- /// </summary>
73- /// <typeparam name="T">Type of the target instance built with parsed value.</typeparam>
74- /// <param name="result">An verb result instance.</param>
75- /// <param name="action">The <see cref="Func{T, Task}"/> to execute.</param>
76- /// <returns>The same <paramref name="result"/> instance as a <see cref="Task"/> instance.</returns>
77- public static async Task < ParserResult < object > > WithParsedAsync < T > ( this ParserResult < object > result , Func < T , Task > action )
78- {
79- if ( result is Parsed < object > parsed )
80- {
81- if ( parsed . Value is T )
82- {
83- await action ( ( T ) parsed . Value ) ;
84- }
85- }
86- return result ;
87- }
88-
89-
9051 /// <summary>
9152 /// Executes <paramref name="action"/> if <see cref="CommandLine.ParserResult{T}"/> lacks
9253 /// parsed values and contains errors.
@@ -96,28 +57,11 @@ public static async Task<ParserResult<object>> WithParsedAsync<T>(this ParserRes
9657 /// <param name="action">The <see cref="System.Action"/> delegate to execute.</param>
9758 /// <returns>The same <paramref name="result"/> instance.</returns>
9859 public static ParserResult < T > WithNotParsed < T > ( this ParserResult < T > result , Action < IEnumerable < Error > > action )
99- {
100- if ( result is NotParsed < T > notParsed )
101- {
102- action ( notParsed . Errors ) ;
103- }
104- return result ;
105- }
106-
107- /// <summary>
108- /// Executes asynchronously <paramref name="action"/> if <see cref="CommandLine.ParserResult{T}"/> lacks
109- /// parsed values and contains errors.
110- /// </summary>
111- /// <typeparam name="T">Type of the target instance built with parsed value.</typeparam>
112- /// <param name="result">An <see cref="CommandLine.ParserResult{T}"/> instance.</param>
113- /// <param name="action">The <see cref="System.Func{Task}"/> delegate to execute.</param>
114- /// <returns>The same <paramref name="result"/> instance as a <see cref="Task"/> instance.</returns>
115- public static async Task < ParserResult < T > > WithNotParsedAsync < T > ( this ParserResult < T > result , Func < IEnumerable < Error > , Task > action )
11660 {
11761 var notParsed = result as NotParsed < T > ;
11862 if ( notParsed != null )
11963 {
120- await action ( notParsed . Errors ) ;
64+ action ( notParsed . Errors ) ;
12165 }
12266 return result ;
12367 }
0 commit comments