惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
SegmentFault 最新的问题
Y
Y Combinator Blog
Recorded Future
Recorded Future
博客园 - Franky
I
InfoQ
T
The Blog of Author Tim Ferriss
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
雷峰网
雷峰网
P
Palo Alto Networks Blog
G
GRAHAM CLULEY
Cloudbric
Cloudbric
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
F
Full Disclosure
Google DeepMind News
Google DeepMind News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
Check Point Blog
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
T
Threat Research - Cisco Blogs
U
Unit 42
N
Netflix TechBlog - Medium
The Cloudflare Blog
Spread Privacy
Spread Privacy
Microsoft Azure Blog
Microsoft Azure Blog
美团技术团队
T
Troy Hunt's Blog
Engineering at Meta
Engineering at Meta
H
Heimdal Security Blog
TaoSecurity Blog
TaoSecurity Blog
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tenable Blog
B
Blog
S
Securelist
H
Hacker News: Front Page
Google Online Security Blog
Google Online Security Blog
G
Google Developers Blog

博客园 - 蒋雷军

在2015中使用V12版本的ReportView控件,会导致winform窗体不能正常打开 小心DriveInfo类IsReady属性的较大延迟问题 如何使rdlc报表的表头在每一页都显示 无法将类型为“System.__ComObject”的 COM 对象强制转换为接口类型,原因为没有注册类 引用账户当前已锁定,且可能无法登录”--问题的解决方法(转载) win7访问windows server 2003服务器出现未知的用户名或者错误的密码(转载) NewRowNeeded和UserAddedRow事件以及RowsAdded的区别使用 TabControl控件中TabPage的显示和隐藏 参数计数不匹配,未处理System.Reflection.TargetParameterCountException 设定了自定义属性,来控制控件的宽度或高度,但数据会不正常 如何使一个你没有源代码的DLL文件变为强命名的DLL Windows 7如何限制运行特定的应用程序(转载) 怎么通过应用程序控制策略限制软件运行?(转载) 32位程序在64位电脑下运行, 如何让圆珠笔起死回生 密度采集调整 MIME类型大全 C# 构造函数如何调用父类构造函数或其他构造函数 结合RibbonControl设计MDI窗体,在子窗体关闭后,顶部显示额外的控制栏残影
Overloads和Overrides在元属性继承上的特性
蒋雷军 · 2016-03-05 · via 博客园 - 蒋雷军

元属性继承可以使用IsDefined函数进行判断,先写出结论

如果使用Overrides,则元属性可以继承,除非在使用IsDefined时明确不进行继承判断,如

pFunction.IsDefined(GetType(DisplayNameAttribute), False)

如果使用Overloads,则元属性不能继承,

如下为测试源码:

  1. Sub Main()
  2. 'Dim s As New S3()
  3. 's.Method()
  4. 'CType(s, S2).Method()
  5. 'CType(s, S1).Method()
  6. Dim pFunction As MethodInfo = GetType(S2).GetMethod("Method")
  7. If (pFunction.IsDefined(GetType(DisplayNameAttribute), False)) Then
  8. Console.WriteLine("DisplayName")
  9. Else
  10. Console.WriteLine("No DisplayName")
  11. End If
  12. Console.ReadLine()
  13. End Sub
  14. End Module
  15. Class S1
  16. <DisplayName("s1")>
  17. Public Overridable Sub Method()
  18. Console.WriteLine("这是S1实例方法")
  19. End Sub
  20. End Class
  21. Class S2
  22. Inherits S1
  23. Public Overrides Sub Method()
  24. Console.WriteLine("这是S2实例方法")
  25. End Sub
  26. End Class
  27. Class S3
  28. Inherits S2
  29. 'Public Overloads Sub Method()
  30. ' Console.WriteLine("这是S3实例方法")
  31. 'End Sub
  32. End Class