private static IEnumerable <string> RowsToValues(OrderedFields fields, IEnumerable <Row> rows) { var preProcessed = new string[fields.Count][]; for (var i = 0; i < fields.Count; i++) { var field = fields.ElementAt(i); preProcessed[i] = new[] { field.Alias, field.SimpleType, field.Quote() }; } foreach (var row in rows) { var values = new List <string>(); foreach (var field in preProcessed) { var value = row[field[0]]; if (value == null) { continue; } var strValue = value.ToString(); if (string.IsNullOrWhiteSpace(strValue)) { continue; } if (field[1].StartsWith("bool")) { strValue = strValue.Equals("True", StringComparison.Ordinal) ? "1" : "0"; } values.Add(field[2] == string.Empty ? strValue : string.Concat(field[2], strValue.Replace("'", "''"), field[2])); } yield return(string.Join(",", values)); } }
private static IEnumerable<string> RowsToValues(OrderedFields fields, IEnumerable<Row> rows) { var preProcessed = new string[fields.Count][]; for (var i = 0; i < fields.Count; i++) { var field = fields.ElementAt(i); preProcessed[i] = new[] { field.Alias, field.SimpleType, field.Quote() }; } foreach (var row in rows) { var values = new List<string>(); foreach (var field in preProcessed) { var value = row[field[0]]; if (value == null) continue; var strValue = value.ToString(); if (string.IsNullOrWhiteSpace(strValue)) continue; if (field[1].StartsWith("bool")) { strValue = strValue.Equals("True", StringComparison.Ordinal) ? "1" : "0"; } values.Add(field[2] == string.Empty ? strValue : string.Concat(field[2], strValue.Replace("'", "''"), field[2])); } yield return string.Join(",", values); } }