attributesclassusec.vb

来自「大名鼎鼎的mono是.NET平台的跨平台(支持linux」· VB 代码 · 共 40 行

VB
40
字号
'Author: Ritvik Mayank <mritvik@novell.com>'Copyright (C) 2005 Novell Inc. (http://www.novell.com)' multiple-use for derived takes both the attributesImports System<AttributeUsage(AttributeTargets.Class, AllowMultiple:=True, _                Inherited:=True)> _Class MultiUseAttribute    Inherits System.Attribute    Public Sub New(ByVal Value As Boolean)    End SubEnd Class<AttributeUsage(AttributeTargets.Class, Inherited:=True)> _Class SingleUseAttribute    Inherits Attribute    Public Sub New(ByVal Value As Boolean)    End SubEnd Class<SingleUse(True), MultiUse(True)> Class BaseEnd Class<SingleUse(False), MultiUse(False)> _Class Derived    Inherits BaseEnd ClassModule Test    Function Main() As Integer        Dim type As Type = GetType(Derived)        Dim arr() As Object = _        type.GetCustomAttributes(GetType(Attribute), True)        If arr.Length <> 3 Then            Throw New Exception("multiple-use attribute is inherited on a derived type can take both attributes. expected total attributes = 3 but got " & arr.Length)        End If    End FunctionEnd Module

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?