private static void ProcessTransactionColumn(XElement td, int currentColumn, SmileStatementTransaction s, List<SmileStatementTransaction> sList) { Action<string>[] columnAssignments = { value => s.TransactionDate = value, value => s.TransactionDetail = value, value => s.AmountAsCredit = value, value => s.AmountAsDebit = value, value => s.RunningBalance = value }; // No default - assumes that 4 is the highest column here (if not will throw an array out of bounds exception) columnAssignments[currentColumn](string.IsNullOrWhiteSpace(td.Value) ? string.Empty : td.Value); // Check against last index of column assignments (so adding another column does not change this code) if (currentColumn != columnAssignments.Length - 1) return; // TransactionDetail containing BROUGHT FORWARD is not a regular row if (!s.TransactionDetail.Contains("FORWARD")) { sList.Add(s); } }
public List<SmileStatementTransaction> ConvertStatementFromTidiedHtmlToSmileStatement(XDocument xml) { SmileStatementTransaction s = null; var sList = new List<SmileStatementTransaction>(); var currentColumn = 1; var inners = xml.Descendants("td").Where(x => x.HasAttributes && x.FirstAttribute.Value.Contains("summaryDetail")); foreach (var td in inners) { if (td.FirstAttribute.Value.Equals("summaryDetailC")) { s = new SmileStatementTransaction(); currentColumn = 0; // Changed to index columns starting from 0 } else { currentColumn++; } ProcessTransactionColumn(td, currentColumn, s, sList); } return sList; }