Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

634
Visualizações
How to make FileHelpers ignore columns after the defined columns? (i.e. ignore columns at the end)

Suppose I have the following FileHelpers Record definition:

[DelimitedRecord(",")]
[IgnoreEmptyLines]
public class TestRecord
{
    [FieldCaption("A")]
    [FieldQuoted(QuoteMode.OptionalForBoth)]
    public string A;

    [FieldCaption("B")]
    [FieldQuoted(QuoteMode.OptionalForBoth)]
    public string B;

    [FieldCaption("C")]
    [FieldQuoted(QuoteMode.OptionalForBoth)]
    public string C;
}

I am only interested in columns A,B,C. Any columns that follow them can be ignored. So for example, I would like it to be possible to handle data like this:

A,B,C,D,E
TestA1,TestB1,TestC1,TestD1,TestE1
TestA2,TestB1,TestC1,TestD1,TestE1

or:

A,B,C,D
TestA1,TestB1,TestC1,TestD1
TestA2,TestB1,TestC1,TestD1

or:

A,B,C
TestA1,TestB1,TestC1
TestA2,TestB1,TestC1
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Just add an extra string[] field to the end of your class and mark it [FieldOptional].

[DelimitedRecord(",")]
[IgnoreEmptyLines]
public class TestRecord
{
    [FieldCaption("A")]
    [FieldQuoted(QuoteMode.OptionalForBoth)]
    public string A;

    [FieldCaption("B")]
    [FieldQuoted(QuoteMode.OptionalForBoth)]
    public string B;

    [FieldCaption("C")]
    [FieldQuoted(QuoteMode.OptionalForBoth)]
    public string C;

    [FieldOptional]
    public string[] EverythingElse;
}

class Program
{
    static void Main(string[] args)
    {
        var engine = new FileHelperEngine<TestRecord>();
        var records = engine.ReadString("TestA1,TestB1,TestC1,TestD1,TestE1");
        
        Debug.Assert(records.Count() == 1);
        Debug.Assert(records[0].A == "TestA1");
        Debug.Assert(records[0].B == "TestB1");
        Debug.Assert(records[0].C == "TestC1");

        Console.WriteLine("All OK");
        Console.ReadLine();
    }
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda