本文整理汇总了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
开发者ID:VB.NET开发者,项目名称:System.Reflection,代码行数:55,代码来源:MemberInfo.IsDefined
注:本文中的System.Reflection.MemberInfo.IsDefined方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论