如何检查是否一个类型的标有一个属性? [英] How to check if a type is marked with an attribute?
本文介绍了如何检查是否一个类型的标有一个属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否需要反思?
推荐答案
是:
Attribute.IsDefined(yourType, attributeType);
除了 [Serializable接口]
,可能的也的是 yourType.IsSerializable
(如果您检查白细胞介素, [Serializable接口]
不的实际上的被写入作为一个属性 - 有专门的类型修饰符;这两种方法工作得很好,虽然)
Except for [Serializable]
, which might also be yourType.IsSerializable
(if you check the IL, [Serializable]
doesn't actually get written as an attribute - there is a special type modifier; either approach works fine, though).
这篇关于如何检查是否一个类型的标有一个属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文