本文整理匯總了VB.NET中System.Reflection.MemberInfo.IsDefined方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET MemberInfo.IsDefined方法的具體用法?VB.NET MemberInfo.IsDefined怎麽用?VB.NET MemberInfo.IsDefined使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Reflection.MemberInfo
的用法示例。
在下文中一共展示了MemberInfo.IsDefined方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: MyClass1
' 導入命名空間
Imports System.Reflection
' Define a custom attribute with one named parameter.
<AttributeUsage(AttributeTargets.All)> Public Class MyAttribute
Inherits Attribute
Private myName As String
Public Sub New(ByVal name As String)
myName = name
End Sub
Public ReadOnly Property Name() As String
Get
Return myName
End Get
End Property
End Class
' Define a class that has the custom attribute associated with one of its members.
Public Class MyClass1
<MyAttribute("This is an example attribute.")> Public Sub MyMethod(ByVal i As Integer)
Return
End Sub
End Class
Public Class MemberInfo_GetCustomAttributes_IsDefined
Public Shared Sub Main()
Try
' Get the type of MyClass1.
Dim myType As Type = GetType(MyClass1)
' Get the members associated with MyClass1.
Dim myMembers As MemberInfo() = myType.GetMembers()
' Display the attributes for each of the members of MyClass1.
Dim i As Integer
For i = 0 To myMembers.Length - 1
' Display the attribute if it is of type MyAttribute.
If myMembers(i).IsDefined(GetType(MyAttribute), False) Then
Dim myAttributes As [Object]() = myMembers(i).GetCustomAttributes(GetType(MyAttribute), False)
Console.WriteLine(ControlChars.Cr + "The attributes of type MyAttribute for the member {0} are: " + ControlChars.Cr, myMembers(i))
Dim j As Integer
For j = 0 To myAttributes.Length - 1
' Display the value associated with the attribute.
Console.WriteLine("The value of the attribute is : ""{0}""", CType(myAttributes(j), MyAttribute).Name)
Next j
End If
Next i
Catch e As Exception
Console.WriteLine("An exception occurred: {0}", e.Message)
End Try
End Sub
End Class