本文整理匯總了VB.NET中System.Type.GetField方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Type.GetField方法的具體用法?VB.NET Type.GetField怎麽用?VB.NET Type.GetField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Type
的用法示例。
在下文中一共展示了Type.GetField方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: MyFieldClassA
' 導入命名空間
Imports System.Reflection
Public Class MyFieldClassA
Public Field As String = "A Field"
End Class
Public Class MyFieldClassB
Private myField As String = "B Field"
Public Property Field() As String
Get
Return myField
End Get
Set(ByVal Value As String)
If myField <> value Then
myField = value
End If
End Set
End Property
End Class
Public Class MyFieldInfoClass
Public Shared Sub Main()
Dim myFieldObjectB As New MyFieldClassB()
Dim myFieldObjectA As New MyFieldClassA()
Dim myTypeA As Type = GetType(MyFieldClassA)
Dim myFieldInfo As FieldInfo = myTypeA.GetField("Field")
Dim myTypeB As Type = GetType(MyFieldClassB)
Dim myFieldInfo1 As FieldInfo = myTypeB.GetField("myField", _
BindingFlags.NonPublic Or BindingFlags.Instance)
Console.WriteLine("The value of the public field is: '{0}'", _
myFieldInfo.GetValue(myFieldObjectA))
Console.WriteLine("The value of the private field is: '{0}'", _
myFieldInfo1.GetValue(myFieldObjectB))
End Sub
End Class