Skip to content

Instantly share code, notes, and snippets.

@underwhelmed
Created January 26, 2011 16:41
Show Gist options
  • Save underwhelmed/796968 to your computer and use it in GitHub Desktop.
Save underwhelmed/796968 to your computer and use it in GitHub Desktop.
How I would implement storing the record line with the storage object using FileHelpers
using System;
using FileHelpers;
using NUnit.Framework;
namespace FileHelpers.Tests.Converters
{
[TestFixture]
public class RecordStringConverter.cs
{
FileHelperEngine<UserRecord> engine = new FileHelperEngine<UserRecord>();
[Test]
public void Test();
{
string sampleData =
@"123456;Phillip ;Fry
098765;Turanga ;Leela
110110;Bender ;Rodriguez
INVALID ID FOR MY DATA SET;Zapp ;Brannigan";
UserRecord[] users = engine.ReadString(sampleData);
foreach (var user in users)
{
int login;
if (!int.TryParse(user.LoginId, out login))
{
Assert.AreEqual("INVALID ID FOR MY DATA SET;Zapp ;Brannigan", user.RecordString) //NOTE the spaces
}
}
}
[DelimitedRecord(";")]
private class UserRecord
{
[FieldTrim(TrimMode.Both)]
public string LoginId;
[FieldTrim(TrimMode.Both)]
public string FirstName;
[FieldTrim(TrimMode.Both)]
public string LastName;
//possible implementation
//[RecordString]
//public string RecordString;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment