Created
March 9, 2021 20:37
-
-
Save pedroinfo/e154a7a547f1b095450fec4200427f1a to your computer and use it in GitHub Desktop.
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
using FileHelpers; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
//Nuget: Install-Package FileHelpers | |
namespace Bingo | |
{ | |
[FixedLengthRecord] | |
public class Pessoa | |
{ | |
[FieldFixedLength(5)] | |
public string PessoaId { get; set; } | |
[FieldFixedLength(20)] | |
public string Nome { get; set; } | |
[FieldFixedLength(14)] | |
public string Documento { get; set; } | |
} | |
public class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var listPessoa = new List<Pessoa> | |
{ | |
new Pessoa | |
{ | |
PessoaId = "1", | |
Nome = "Priscila", | |
Documento = "123334" | |
}, | |
new Pessoa | |
{ | |
PessoaId = "2", | |
Nome = "Maria", | |
Documento = "14234234" | |
}, | |
new Pessoa | |
{ | |
PessoaId = "3", | |
Nome = "Roberta", | |
Documento = "8188234" | |
} | |
}; | |
var engine = new FileHelperEngine<Pessoa>(); | |
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "saida.txt"); | |
engine.WriteFile(path, listPessoa) ; | |
Console.WriteLine($"Arquivo gerado: {path}"); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1 Priscila 123334
2 Maria 14234234
3 Roberta 8188234