public async IAsyncEnumerable <Transaction> Parse(StreamReader sourceString) { var xmlSerializer = new XmlSerializer(typeof(TransactionsList)); var list = (TransactionsList)xmlSerializer.Deserialize(sourceString); foreach (var xmlItem in list.Transactions) { if (_validator.TryValidateItem(xmlItem)) { yield return(await Task.FromResult(xmlItem.ToTransactionModel())); } } _validator.ThrowIfValidationEverFailed(); }
public async IAsyncEnumerable <Transaction> Parse(StreamReader sourceStream) { using var csvReader = new CsvReader(sourceStream, new CsvConfiguration(CultureInfo.InvariantCulture) { HasHeaderRecord = false, IgnoreBlankLines = true, Delimiter = ",", TrimOptions = TrimOptions.InsideQuotes | TrimOptions.Trim, CountBytes = true, Encoding = Encoding.UTF8 }); while (await csvReader.ReadAsync()) { var csvItem = csvReader.GetRecord <TransactionFormatCsv>(); if (_validator.TryValidateItem(csvItem)) { yield return(csvItem.ToTransactionModel()); } } _validator.ThrowIfValidationEverFailed(); }