I have a struct with a lot of members. I need to filter grid. Now i have something like this :
foreach(string word in words)
{
if (c.Caption == "ID")
FilteredList.AddRange(BaseList.FindAll(x => x.ID == Int32.Parse(word)));
else if (c.Caption == "Serial"
FilteredList.AddRange(BaseList.FindAll(x => x.Serial == word));
else if (c.Caption == "Phone")
FilteredList.AddRange(BaseList.FindAll(x => x.Phone == word));
etc...
}
Is it possible to create something like this ?
foreach(string word in words)
{
var propertyInfo = object.GetType().GetMember(word);
FilteredList.AddRange(BaseList.FindAll(x => x.propertyInfo == word));
}
Aucun commentaire:
Enregistrer un commentaire