0

I have a DTO called ListaAvdArquivoPagamentoDetDTO.

 public class ListaAvdArquivoPagamentoDetDTO  
 {
        public List<AvdArquivoPagamentoDet> AvdArquivoPagamentoDets { get; set;}
        public decimal TotalNfsLancadas { get; set;}

 }

I made a method to retrieve data and make a new instance of my DTO, however everrything is working good till we reach "listaAvdArquivoPagamentoDet.AvdArquivoPagamentoDets.AddRange(listaPagamentoDet);", when we reach that line the new exception error ocurs.

public ListaAvdArquivoPagamentoDetDTO listarAvdArquivoPagamentoDet(DadosAmbiente amb, int codigoAvdArquivoPagamento)
{
     var listaAvdArquivoPagamentoDet = new ListaAvdArquivoPagamentoDetDTO();

     InserirListaDeAvdArquivoPagamentoDet(listaAvdArquivoPagamentoDet, amb, codigoAvdArquivoPagamento);
     InserirValorTotalNfs(listaAvdArquivoPagamentoDet, amb, codigoAvdArquivoPagamento);

     return listaAvdArquivoPagamentoDet;
 }

 public void InserirListaDeAvdArquivoPagamentoDet(ListaAvdArquivoPagamentoDetDTO listaAvdArquivoPagamentoDet, DadosAmbiente amb, int codigoAvdArquivoPagamento)
 {

     var listaPagamentoDet = _repAvdArquivoPagamentoDet.Recuperar().Where(p => p.CodigoArquivo == codigoAvdArquivoPagamento &&
                                                                               p.CodigoEmpresa == amb.idEmpresa).ToList();

     if(listaPagamentoDet == null)
     {
        return;
     }

     listaAvdArquivoPagamentoDet.AvdArquivoPagamentoDets.AddRange(listaPagamentoDet);

  }

I tried a cople of things, I expect to amake it work using the most I can from Clean Code principles.

  • The `AvdArquivoPagamentoDets` property is never initialized to an instance of anything. Depending on the C# version used (you seem to be using... many of them), you can do that inline: `public List AvdArquivoPagamentoDets { get; set;} = new List();` Or initialize it in the object's constructor. – David Jul 11 '23 at 13:46

0 Answers0