如果使用Overrides,则元属性可以继承,除非在使用IsDefined时明确不进行继承判断,如
如果使用Overloads,则元属性不能继承,
Sub Main()‘Dim s As New S3()‘s.Method()‘CType(s, S2).Method()‘CType(s, S1).Method()Dim pFunction As MethodInfo = GetType(S2).GetMethod("Method")If (pFunction.IsDefined(GetType(DisplayNameAttribute), False)) ThenConsole.WriteLine("DisplayName")ElseConsole.WriteLine("No DisplayName")End IfConsole.ReadLine()End SubEnd ModuleClass S1<DisplayName("s1")>Public Overridable Sub Method()Console.WriteLine("这是S1实例方法")End SubEnd ClassClass S2Inherits S1Public Overrides Sub Method()Console.WriteLine("这是S2实例方法")End SubEnd ClassClass S3Inherits S2‘Public Overloads Sub Method()‘ Console.WriteLine("这是S3实例方法")‘End SubEnd Class
原文:http://www.cnblogs.com/wene/p/5246165.html