FileHelpers - Handle Missing Values with Nullable

  • Contact / Feedback
  • Introduction
  • Download
  • Quick Start
  • Must Read
  • Examples
    • QuickStart
      • Read Delimited File
      • Write Delimited File
      • Read Fixed File
      • Write Fixed File
      • Read or Write Record by Record
      • Autoproperties
    • Missing Values
      • Handle Missing Values with Nullable
      • Handle Missing Values With FieldNullValue
    • Attributes
      • FieldTrim
      • FieldOrder
      • FixedLengthRecord FixedMode.AllowLessChars
    • Converters
      • Enum Converter
      • Custom Converter
    • Events And Notification
      • INotifyRead Interface
      • INotifyWrite Interface
      • Before/After Read Event Handling
      • Before/After Write Event Handling
    • ErrorHandling
      • ErrorMode.ThrowException
      • ErrorMode.IgnoreAndContinue
      • ErrorMode SaveAndContinue
    • Advanced
      • Dynamic Engine Options
      • Multiple Delimiters
      • Multi Record Processing
      • Smart Format Detector
    • Sorting
      • Sort Big File with Record Class
      • Sort Big File without Record Class 1
      • Sort Big File without Record Class 2
    • MasterDetail
      • Master Detail Custom Selector
      • Master Detail Common Selector
  • Credits
  • Invite us a beer
  • Contribute
  • Source Code
  • Api Docs (Sandcastle)
  1. Examples
  2. Missing Values
  3. Handle Missing Values with Nullable
Previous: Autoproperties
Next: Handle Missing Values With FieldNullValue
Click button to edit
Missing Values: Handle Missing Values with Nullable
Using Nullable for missing values

If your files contain a field that can be empty

Input.txt
10248|VINET|04071996|32.38
10249|TOMSP||11.61
10250|HANAR|08071996|65.83
10251|VICTE||41.34
RecordClass.cs
[DelimitedRecord("|")]
public class Orders
{
    public int OrderID;

    public string CustomerID;

    [FieldConverter(ConverterKind.Date, "ddMMyyyy")]
    public DateTime? OrderDate;

    public decimal? Freight;
}
Example.cs
var engine = new FileHelperEngine<Orders>();
var records = engine.ReadFile("Input.txt");

foreach (var record in records) {
    Console.WriteLine(record.CustomerID);
    Console.WriteLine(record.OrderDate);
    Console.WriteLine(record.Freight);
}
Console
VINET
04/07/1996 12:00:00 a.m.
32,38
TOMSP

11,61
HANAR
08/07/1996 12:00:00 a.m.
65,83
VICTE

41,34
Copyright © 2020 Devoo - Marcos Meli All rights reserved. Template Design by GeeksLabs