// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information. using System; using System.Collections.Generic; using System.Threading.Tasks; namespace CommandLine { public static partial class ParserResultExtensions { #if !NET40 /// /// Executes asynchronously if contains /// parsed values. /// /// Type of the target instance built with parsed value. /// An instance. /// The to execute. /// The same instance as a instance. public static async Task> WithParsedAsync(this ParserResult result, Func action) { if (result is Parsed parsed) { await action(parsed.Value); } return result; } /// /// Executes asynchronously if parsed values are of . /// /// Type of the target instance built with parsed value. /// An verb result instance. /// The to execute. /// The same instance as a instance. public static async Task> WithParsedAsync(this ParserResult result, Func action) { if (result is Parsed parsed) { if (parsed.Value is T value) { await action(value); } } return result; } /// /// Executes asynchronously 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 as a instance. public static async Task> WithNotParsedAsync(this ParserResult result, Func, Task> action) { if (result is NotParsed notParsed) { await action(notParsed.Errors); } return result; } #endif } }