如何通过反射过滤任何属性的集合?
我有 IEnumerable 集合。我想创建这样的方法:
public IEnumerable<object> Try_Filter(IEnumerable<object> collection, string property_name, string value)
{
//If object has property with name property_name,
// return collection.Where(c => c.Property_name == value)
}
可能吗?我正在使用 C# 4.0。 谢谢!
I have IEnumerable collection. I want to create such method:
public IEnumerable<object> Try_Filter(IEnumerable<object> collection, string property_name, string value)
{
//If object has property with name property_name,
// return collection.Where(c => c.Property_name == value)
}
Is it possible? I'm using C# 4.0.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
测试:
虽然,这对于大型集合来说会非常慢
Try this:
Tested with:
Although, this will be very slow for large collections