在哪里排除反射中的属性 [英] .Where to exclude properties in reflection
本文介绍了在哪里排除反射中的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码以及称为string[]
的被排除的代码.我想获取任何类的所有属性,但在排除中专门调用的属性除外.
I have the following code as well as a string[]
called excluded. I want to grab all of the properties of any class, except the ones specifically called out in excluded.
是否有一个.Where
允许我的Propertyinfo[]
不包含排除的属性?
Is there a .Where
that will allow my Propertyinfo[]
to not contain the excluded properties?
PropertyInfo[] names = typeof(S).GetProperties();
推荐答案
简单地:
typeof(S).GetProperties().Where(p => !excluded.Contains(p.Name)).ToArray()
这篇关于在哪里排除反射中的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文