我有一個列表,我想基於KeyValuePair列表進行過濾。 KeyValuePair中的所有鍵都存在於對象中。基於KeyValuePairs的過濾器列表
所以我們可以說我有這個類對象的列表:
public class filters
{
public string Name { get; set; }
public string Age { get; set; }
public string Country { get; set; }
}
而且我有一個KeyValuePair有:
Key: "Name", Value: "test"
Key: "Country", Value: "SE"
是否有可能產生一些不同於那種LINQ謂詞KeyValuePair可用作list.Where(predicate)
,謂詞將與我寫list.Where(c => c.Name == "test" && c.Country == "SE")
時相同?
或者我該如何處理?
您是否嘗試了反射? – qxg
不知道我會如何使用反射這個 –
'var keySet = new Dictionary {{「Name」,「test」}}; Predicate condition =(c)=> c.Name == keySet [「Name」] && c.Country == keySet [「Country」]; list.Where(condition);'這是你感興趣的嗎? –
CarbineCoder