从超类扩展的类属性访问 [英] Access on attribute of extended class from SuperClass
本文介绍了从超类扩展的类属性访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下类和我需要知道,如果DocPage类有属性SessionRequired进入方法Render():
I have the following classes and I need to know if DocPage class have the attribute SessionRequired into the method Render():
public class DocPageBase
{
void Render()
{
// Have extended class SessionRequired?
}
}
[SessionRequired]
public class DocPage : DocPageBase
{
// Some properties and methods
}
感谢您的帮助!
问候,
杰拉德
推荐答案
您会使用的GetType()
来得到实际的类型,然后的 Type.IsDefined
一>检查属性的presence。
You'd use GetType()
to get the actual type, and then Type.IsDefined
to check for the presence of the attribute.
void Render()
{
if (GetType().IsDefined(typeof(SessionRequiredAttribute), false)
{
...
}
}
这篇关于从超类扩展的类属性访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文