-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Sep * use sep 0.1.0
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using nietras.SeparatedValues; | ||
|
||
namespace Knapcode.NCsvPerf.CsvReadable | ||
{ | ||
/// <summary> | ||
/// Package: https://www.nuget.org/packages/Sep/ | ||
/// Source: https://github.com/nietras/Sep | ||
/// </summary> | ||
public class Sep : ICsvReader | ||
{ | ||
private readonly ActivationMethod _activationMethod; | ||
|
||
public Sep(ActivationMethod activationMethod) | ||
{ | ||
_activationMethod = activationMethod; | ||
} | ||
|
||
public List<T> GetRecords<T>(MemoryStream stream) where T : ICsvReadable, new() | ||
{ | ||
var activate = ActivatorFactory.Create<T>(_activationMethod); | ||
var allRecords = new List<T>(); | ||
|
||
using var reader = nietras.SeparatedValues.Sep.Reader(o => o with | ||
{ | ||
HasHeader = false, | ||
CreateToString = SepToString.PoolPerCol(maximumStringLength: 128), | ||
}) | ||
.From(stream); | ||
|
||
// Due to how NCsvPerf code is factored and that Sep uses ref | ||
// structs, the code below is different from normal Sep usage. | ||
Func<int, string> toString = reader.ToString; | ||
foreach (var row in reader) | ||
{ | ||
var record = activate(); | ||
record.Read(toString); | ||
allRecords.Add(record); | ||
} | ||
|
||
return allRecords; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters