简体   繁体   English

在C#中,如何检查属性上是否应用了XmlIgnore属性?

[英]In C# how can I check that XmlIgnore attribute is applied on a property or not?

I want to check propertyInfo to determine whether or not XmlIgnore attribute is applied to a given property. 我想检查propertyInfo以确定是否将XmlIgnore属性应用于给定属性。 How can I do this? 我怎样才能做到这一点?

bool b = type.GetProperty("MyProp")
             .GetCustomAttributes(false)
             .Any(a => a is XmlIgnoreAttribute);
typeof(string).GetProperty("Length").GetCustomAttributes(typeof(some attr))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM