.在反射中排除属性的地方

.Where to exclude properties in reflection

我有以下代码以及一个名为 excluded 的 string[]。我想获取任何 class 的所有属性,除了在 excluded 中特别指出的那些。

是否有 .Where 允许我的 Propertyinfo[] 不包含排除的属性?

PropertyInfo[] names = typeof(S).GetProperties();

这样的事情可能会完成这项工作:

PropertyInfo[] names = typeof(S).GetProperties().Where(c => !excluded.Contains(c.Name)).ToArray();

简单:

typeof(S).GetProperties().Where(p => !excluded.Contains(p.Name)).ToArray()