本文整理匯總了VB.NET中System.Type.GetFields方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Type.GetFields方法的具體用法?VB.NET Type.GetFields怎麽用?VB.NET Type.GetFields使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Type
的用法示例。
在下文中一共展示了Type.GetFields方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: FieldInfo_IsSpecialName
' 導入命名空間
Imports System.Reflection
Imports System.ComponentModel.Design
Class FieldInfo_IsSpecialName
Public Shared Sub Main()
Try
' Get the type handle of a specified class.
Dim myType As Type = GetType(ViewTechnology)
' Get the fields of a specified class.
Dim myField As FieldInfo() = myType.GetFields()
Console.WriteLine(ControlChars.Cr + "Displaying fields that have SpecialName attributes:" + ControlChars.Cr)
Dim i As Integer
For i = 0 To myField.Length - 1
' Determine whether or not each field is a special name.
If myField(i).IsSpecialName Then
Console.WriteLine("The field {0} has a SpecialName attribute.", myField(i).Name)
End If
Next i
Catch e As Exception
Console.WriteLine("Exception : {0} ", e.Message.ToString())
End Try
End Sub
End Class
示例2: AttributesSample
' 導入命名空間
Imports System.Reflection
Class AttributesSample
Public Sub Mymethod(ByVal int1m As Integer, ByRef str2m As String, ByRef str3m As String)
str2m = "in Mymethod"
End Sub
Public Shared Function Main(ByVal args() As String) As Integer
Console.WriteLine("Reflection.MethodBase.Attributes Sample")
' Get the type.
Dim MyType As Type = Type.GetType("AttributesSample")
' Get the method Mymethod on the type.
Dim Mymethodbase As MethodBase = MyType.GetMethod("Mymethod")
' Display the method name.
Console.WriteLine("Mymethodbase = {0}.", Mymethodbase)
' Get the MethodAttribute enumerated value.
Dim Myattributes As MethodAttributes = Mymethodbase.Attributes
' Display the flags that are set.
PrintAttributes(GetType(System.Reflection.MethodAttributes), CInt(Myattributes))
Return 0
End Function 'Main
Public Shared Sub PrintAttributes(ByVal attribType As Type, ByVal iAttribValue As Integer)
If Not attribType.IsEnum Then
Console.WriteLine("This type is not an enum.")
Return
End If
Dim fields As FieldInfo() = attribType.GetFields((BindingFlags.Public Or BindingFlags.Static))
Dim i As Integer
For i = 0 To fields.Length - 1
Dim fieldvalue As Integer = CType(fields(i).GetValue(Nothing), Int32)
If (fieldvalue And iAttribValue) = fieldvalue Then
Console.WriteLine(fields(i).Name)
End If
Next i
End Sub
End Class