FileHelpers - Autoproperties

  • 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. QuickStart
  3. Autoproperties
Previous: Read or Write Record by Record
Next: Handle Missing Values with Nullable
Click button to edit
QuickStart: Autoproperties
You can use autoproperties instead of fields

If you have a source file like this, separated by a |:

Input.txt
10248|VINET|04071996|32.38
10249|TOMSP|05071996|11.61
10250|HANAS|08071996|65.83
10251|VICTE|08071996|41.34

You can use autoproperties but for the moment you can't use Converters

RecordClass.cs
[DelimitedRecord("|")]
public class Orders
{
    public int OrderID { get; set; }

    public string CustomerID { get; set; }

    public string OrderDate { get; set; }

    public string Freight { get; set; }
}
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
04071996
32.38
TOMSP
05071996
11.61
HANAS
08071996
65.83
VICTE
08071996
41.34
Copyright © 2020 Devoo - Marcos Meli All rights reserved. Template Design by GeeksLabs