FileHelpers - FieldOrder

  • 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. Attributes
  3. FieldOrder
Previous: FieldTrim
Next: FixedLengthRecord FixedMode.AllowLessChars
Click button to edit
Attributes: FieldOrder
Force field order with [FieldOrder] attribute:
//-> You first declare a Record Mapping class:
Input.txt
10248|VINET|04071996|32.38
10249|TOMSP|05071996|11.61
10250|HANAS|08071996|65.83
10251|VICTE|08071996|41.34
RecordClass.cs
[DelimitedRecord("|")]
public class Orders
{
    [FieldOrder(20)]
    public string CustomerID;

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

    [FieldConverter(ConverterKind.Decimal, ".")] // The decimal separator is "."
    [FieldOrder(40)]
    public decimal Freight;

    [FieldOrder(10)]
    public int OrderID;
}
//-> The FileHelperEngine to process the file:
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.ToString("dd/MM/yyyy"));
    Console.WriteLine(record.Freight);
}
Console
VINET
04/07/1996
32,38
TOMSP
05/07/1996
11,61
HANAS
08/07/1996
65,83
VICTE
08/07/1996
41,34
Copyright © 2020 Devoo - Marcos Meli All rights reserved. Template Design by GeeksLabs