I have the following code snippet:
var filter = new { categoria = 1, cond2 = foo, ... };
p = new ProdutoBusiness().listarProdutos( filter ).ToList();
I wanted to work with this anonymous type as a parameter to filter, but I do not know how to get this type of value in the referenced method:
public IEnumerable<Produto> listarProdutos( tipo???? filter = null) {
My intention is to change the query according to what comes in the filter. For example:
if(filter != null){
if(filter.categoria != ""){
query = from P in con.produto
join C in con.categoria on P.categoriaID equals C.categoriaID
where P.ativo == true
&& P.categoriaID == filter.categoria
orderby P.nome ascending
select P;
}
[...]
}
Any ideas / suggestions?
/ ************* /
If someone has the same question with these ' dynamic ' types mentioned in the answer, I have resolved this:
Popular the object:
var filter = new { categoria = 1, cond2 = foo, ... }
Receiving the parameter:
public IEnumerable<Produto> listarProdutos( dynamic filter = null) {}
Getting the 'key' value:
var fCategoria = filter.GetType( ).GetProperty( "categoria" ).GetValue( filter, null );