2
I am trying to create a method that receives an anonymous type (LINQ query)
(Please correct me if the term tipo anônimo (anonymous types)
is incorrect)
MinhaLista (produtos.Select(p => new {p.Id, p.Estoque})
I asked Visual Studio to create the method automatically and I was generated:
public static object MinhaLista (object @select)
I would like the method to be able to do:
foreach (var produto in produtos)
{
Debug.WriteLine(produto.Id);
}
What is the correct way to define a method to receive this tipo anônimo (anonymous types)
?
This is one way, but it depends on what you want to do. I don’t know if I can answer this just with this information.
– Maniero
I edited with what I would like to do in the method. @bigown
– rubStackOverflow
Now the question has become totally meaningless.
– Maniero
How could I have access to the data passed by
MinhaLista (produtos.Select(p => new {p.Id, p.Estoque})
in my methodMinhaLista (object @select) {}
– rubStackOverflow
your method has to be even Anonymous? , could not create a class that had the types you are going through?
– Marco Souza
According to your question, I believe my answer is correct. Because I’m showing you how to get properties from an anonymous object. In addition I still prove the operation in fiddle
– Joel Ramos Michaliszen