Good afternoon!
I would like to ask a question, I am developing a collection code and at a certain point if it takes a for iterate the values in the list and then save the information in an item ... Until then, however, the problem arises because the frame in which I am collecting does not have a certain amount of lines for collection, it can be from 1 line to 50 (example).
At this moment my logic is broken, because I can not create conditions following a minimal logic, I would like to know what the possibility of leaving it to be auto-interpretative, when it goes through the values, the next lines of the array that it reads, automatically recognizes the value and allocates the specific var.
I just did not post the code because I do not know if it would help a lot, but it follows the excerpt from the for and the link of the page I am capturing:
foreach (var acumulador in item)
{
var texto = acumulador.SelectNodes("//*[contains(text(),'Código')]/../../descendant-or-self::tr|//*[@class='RelLinhaBranca'][1]//*[contains(text(),'Código')]/../../following-sibling::tr");
for (int j = 0; j < texto.Count; j++)
{
if (texto == null || texto.ToString() == "")
{
continue;
}
else
{
itens.favorecido = new Favorecido() { nome = texto[j + 1].InnerText.CopyUntil("- V").Trim() };
itens.marca = texto[j + 2].InnerText.CopyAfter("Marca").Trim();
itens.valor_unitario = decimal.Parse(texto[j + 3].InnerText.CopyBetween("R$", "Valor").Replace(",", "").Trim(), new CultureInfo("pt-BR"));
itens.valor_total = decimal.Parse(texto[j + 3].InnerText.CopyAfter("Total").Replace("R$", "").Replace(",", "").Trim(), new CultureInfo("pt-BR"));
itens.num_item = texto[j].InnerText.CopyBetween("Código", "Categoria").Trim();
itens.tipo_item = texto[j].InnerText.CopyBetween("Categoria", "Subcategoria").Trim();
itens.descricao = texto[j].InnerText.CopyBetween("Descrição", "Observação").Trim();
itens.quantidade = decimal.Parse(texto[j].InnerText.CopyBetween("Quantidade", "Tipo").Split()[1].Trim(), new CultureInfo("pt-BR"));
itens.unidade = texto[j].InnerText.CopyAfter("Cotacao").Split()[2].Trim();
}
documento.itens.Add(itens);
var ex = "";
}
}