lundi 22 août 2022

linq 'where' with using reflection doesn't work

I'm trying to get items with using linq and reflection:

var type = "Home";
var list = new List<object>();
... some initialization
var selectedItems = list.Where(x => x.GetType().GetProperty("Type").GetValue(x) == type);

into selectedItems I want to get 2 items (that matches condition), but I get one

What's wrong in this code? Thanks in advance





Aucun commentaire:

Enregistrer un commentaire