diff --git a/src/CommandLine/ParserResultExtensions.cs b/src/CommandLine/ParserResultExtensions.cs index 66201dbb..bc9326ea 100644 --- a/src/CommandLine/ParserResultExtensions.cs +++ b/src/CommandLine/ParserResultExtensions.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; namespace CommandLine { @@ -48,6 +49,48 @@ public static ParserResult WithParsed(this ParserResult resul return result; } +#if !NET40 + + /// + /// Executes an async if contains + /// parsed values. + /// + /// Type of the target instance built with parsed value. + /// An instance. + /// The to execute. + /// The same instance. + public static async Task> WithParsedAsync(this ParserResult result, Func action) + { + var parsed = result as Parsed; + if (parsed != null) + { + await action(parsed.Value); + } + return result; + } + + /// + /// Executes an async if parsed values are of . + /// + /// Type of the target instance built with parsed value. + /// An verb result instance. + /// The to execute. + /// The same instance. + public static async Task> WithParsedAsync(this ParserResult result, Func action) + { + var parsed = result as Parsed; + if (parsed != null) + { + if (parsed.Value is T) + { + await action((T)parsed.Value); + } + } + return result; + } + +#endif + /// /// Executes if lacks /// parsed values and contains errors. @@ -66,6 +109,28 @@ public static ParserResult WithNotParsed(this ParserResult result, Acti return result; } +#if !NET40 + + /// + /// Executes an async if lacks + /// parsed values and contains errors. + /// + /// Type of the target instance built with parsed value. + /// An instance. + /// The delegate to execute. + /// The same instance. + public static async Task> WithNotParsedAsync(this ParserResult result, Func, Task> action) + { + var notParsed = result as NotParsed; + if (notParsed != null) + { + await action(notParsed.Errors); + } + return result; + } + +#endif + /// /// Provides a way to transform result data into another value. ///