Skip to content

Instantly share code, notes, and snippets.

@vcaraulean
Created May 6, 2011 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vcaraulean/959133 to your computer and use it in GitHub Desktop.
Save vcaraulean/959133 to your computer and use it in GitHub Desktop.
Path for FileHelpers.com for handling empty (not provided) Guid values
// Replace constructor in line 53 with this one
public FieldNullValueAttribute(Type type, string nullValue)
: this(TypeDescriptor.GetConverter(type).ConvertFromString(nullValue))
{ }
// Unit test to be placed where it's more appropriate
[Test]
public void RunTimeEmptyGuidProperties()
{
var builder = new DelimitedClassBuilder(typeof (EntityWithGuid).Name, "\t");
builder.AddField("Name", typeof (string));
builder.AddField("Id", typeof (Guid));
builder.LastField.FieldNullValue = Guid.Empty;
var engine = new FileHelperEngine(builder.CreateRecordClass())
{
Options = {IgnoreFirstLines = 1}
};
const string inputValue = @"Name Id
first
second ";
Assert.That(engine.ReadString(inputValue).Length, Is.EqualTo(2));
}
public class EntityWithGuid
{
public string Name { get; set; }
public Guid Id { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment