如何检查类型是否标有属性?
它需要反思吗?
是:
Attribute.IsDefined(yourType, attributeType);
除了[Serializable]
,也可能是yourType.IsSerializable
(如果检查IL, [Serializable]
实际上 并没有作为属性写入 – 有一个特殊的类型修饰符;但这两种方法都可以正常工作)。
它需要反思吗?
是:
Attribute.IsDefined(yourType, attributeType);
除了[Serializable]
,也可能是yourType.IsSerializable
(如果检查IL, [Serializable]
实际上 并没有作为属性写入 – 有一个特殊的类型修饰符;但这两种方法都可以正常工作)。