A library for reading and writing LTSV file.
First, install Nuget. Then, install LtsvHelper from the package manager console.
PM> Install-Package LtsvHelper
using (TextReader textReader = new StreamReader("some_path.ltsv"))
using (LtsvReader ltsvReader = new LtsvReader(textReader))
{
IEnumerable<MyRecord> records = ltsvReader.GetRecords<MyRecord>();
}
using (TextReader textReader = new StreamReader("some_path.ltsv"))
using (LtsvReader ltsvReader = new LtsvReader(textReader))
{
while (ltsvReader.Read())
{
MyRecord records = ltsvReader.GetRecord<MyRecord>();
}
}
using (TextReader textReader = new StreamReader("some_path.ltsv"))
using (LtsvReader ltsvReader = new LtsvReader(textReader))
{
while (ltsvReader.Read())
{
string value1 = ltsvReader.GetField("label1");
int value2 = ltsvReader.GetField<int>("label2");
}
}
using (TextWriter textWriter = new StreamWriter("some_path.ltsv"))
using (LtsvWriter ltsvWriter = new LtsvWriter(textWriter))
{
foreach (var item in list)
{
ltsvWriter.WriteRecord(item);
}
}
using (TextWriter textWriter = new StreamWriter("some_path.ltsv"))
using (LtsvWriter ltsvWriter = new LtsvWriter(textWriter))
{
foreach (var item in list)
{
ltsvWriter.WriteField("label1", "value1");
ltsvWriter.WriteField("label2", 10);
ltsvWriter.NextRecord();
}
}
public class MyClassMap : LtsvClassMap<MyClass>
{
public MyClassMap()
{
Map(m => m.Id);
Map(m => m.Name);
}
}
public class MyClassMap : LtsvClassMap<MyClass>
{
public MyClassMap()
{
Map(m => m.Id).Label("id");
Map(m => m.Name).Label("name");
}
}
- Fork it
- Create your feature branch ( git checkout -b my-new-feature )
- Commit your changes ( git commit -am 'Add some feature' )
- Push to the branch ( git push origin my-new-feature )
- Create new Pull Request