本文整理汇总了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