private ResultCollection <TResult> ParseGeneric(Dictionary <IOption, OptionData> optionResults, IEnumerable <string> remainingArgs) { var results = new Dictionary <IOption, IParsingResult>(); foreach (var option in _optionCollections) { if (optionResults.ContainsKey(option.Key)) { var baseOption = option.Key; var optionData = optionResults[option.Key]; if (baseOption is OptionInfo <string> ) { results.Add(option.Key, GetParseResult((OptionInfo <string>)baseOption, optionData)); } else if (baseOption is OptionInfo <List <string> > ) { results.Add(option.Key, GetParseResult((OptionInfo <List <string> >)baseOption, optionData)); } continue; } IResultCollection resultCollection = option.Value.ParseInternal(optionResults); IParsingResult failedResult; if (!resultCollection.Validate(out failedResult)) { results.Add(option.Key, failedResult); } else { results.Add(option.Key, option.Key.Parse(new SuccessfulResultCollection(resultCollection))); } } return(new ResultCollection <TResult>(results, remainingArgs)); }
public SuccessfulResultCollection(IResultCollection collection) { IParsingResult failedResult; if (!collection.Validate(out failedResult)) { throw new ArgumentException($"{nameof(collection)}: all parsing results must be successful. {failedResult.ErrorMessage}."); } _collection = collection; }