Created
May 6, 2011 15:16
-
-
Save vcaraulean/959133 to your computer and use it in GitHub Desktop.
Path for FileHelpers.com for handling empty (not provided) Guid values
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
// Replace constructor in line 53 with this one | |
public FieldNullValueAttribute(Type type, string nullValue) | |
: this(TypeDescriptor.GetConverter(type).ConvertFromString(nullValue)) | |
{ } |
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
// 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