Skip to content

Instantly share code, notes, and snippets.

@pedroinfo
Created March 9, 2021 20:37
Show Gist options
  • Save pedroinfo/e154a7a547f1b095450fec4200427f1a to your computer and use it in GitHub Desktop.
Save pedroinfo/e154a7a547f1b095450fec4200427f1a to your computer and use it in GitHub Desktop.
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();
}
}
}
@pedroinfo
Copy link
Author

1 Priscila 123334
2 Maria 14234234
3 Roberta 8188234

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment