Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit d60fd26

Browse files
committed
DRY single CSV row logic
1 parent a14c230 commit d60fd26

File tree

1 file changed

+3
-21
lines changed

1 file changed

+3
-21
lines changed

src/ServiceStack.Text/CsvReader.cs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -272,21 +272,6 @@ private static List<T> GetSingleRow(IEnumerable<string> rows, Type recordType)
272272
return row;
273273
}
274274

275-
private static List<T> ParseSingleRow(string row, Type recordType)
276-
{
277-
var results = new List<T>();
278-
var itemRows = CsvReader.ParseFields(row);
279-
foreach (var itemRow in itemRows)
280-
{
281-
var to = recordType == typeof(string)
282-
? (T)(object)itemRow
283-
: TypeSerializer.DeserializeFromString<T>(itemRow);
284-
285-
results.Add(to);
286-
}
287-
return results;
288-
}
289-
290275
public static List<T> GetRows(IEnumerable<string> records)
291276
{
292277
var rows = new List<T>();
@@ -375,14 +360,11 @@ public static List<T> Read(List<string> rows)
375360
headers = CsvReader.ParseFields(rows[0], s => s.Trim());
376361
}
377362

378-
if (typeof(T).IsValueType || (typeof(T) == typeof(string)) && rows.Count == 1)
379-
{
380-
return ParseSingleRow(rows[0], typeof(T));
381-
}
382-
383363
if (typeof(T).IsValueType || typeof(T) == typeof(string))
384364
{
385-
return GetSingleRow(rows, typeof(T));
365+
return rows.Count == 1
366+
? GetSingleRow(CsvReader.ParseFields(rows[0]), typeof(T))
367+
: GetSingleRow(rows, typeof(T));
386368
}
387369

388370
for (var rowIndex = headers == null ? 0 : 1; rowIndex < rows.Count; rowIndex++)

0 commit comments

Comments
 (0)