标签:
元属性继承可以使用IsDefined函数进行判断,先写出结论
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)) Then
Console.WriteLine("DisplayName")
Else
Console.WriteLine("No DisplayName")
End If
Console.ReadLine()
End Sub
End Module
Class S1
<DisplayName("s1")>
Public Overridable Sub Method()
Console.WriteLine("这是S1实例方法")
End Sub
End Class
Class S2
Inherits S1
Public Overrides Sub Method()
Console.WriteLine("这是S2实例方法")
End Sub
End Class
Class S3
Inherits S2
‘Public Overloads Sub Method()
‘ Console.WriteLine("这是S3实例方法")
‘End Sub
End Class
标签:
原文地址:http://www.cnblogs.com/wene/p/5246165.html