Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
Public Class Myfielda
Private m_field As String = "A private field"
Public Property Field() As String
Get
Return m_field
End Get
Set(ByVal Value As String)
If m_field <> value Then
m_field = value
End If
End Set
End Property
End Class
Public Class Myfieldb
Private Shared m_field As String = "B private static field"
Public Property Field() As String
Get
Return m_field
End Get
Set(ByVal Value As String)
If m_field <> value Then
m_field = value
End If
End Set
End Property
End Class
Public Class Myfieldinfo
Public Shared Sub Main()
Dim Myfielda As New Myfielda()
Dim Myfieldb As New Myfieldb()
Dim MyTypea As Type = GetType(Myfielda)
Dim Myfieldinfoa As FieldInfo = MyTypea.GetField("m_field", BindingFlags.NonPublic Or BindingFlags.Instance)
Dim MyTypeb As Type = GetType(Myfieldb)
Dim Myfieldinfob As FieldInfo = MyTypeb.GetField("m_field", BindingFlags.NonPublic Or BindingFlags.Static)
Console.WriteLine(MyTypea.FullName)
Console.WriteLine(Myfieldinfoa.GetValue(Myfielda))
Console.WriteLine(Myfieldinfoa.IsStatic)
Console.WriteLine(MyTypeb.FullName)
Console.WriteLine(Myfieldinfob.GetValue(Myfieldb))
Console.WriteLine(Myfieldinfob.IsStatic)
End Sub
End Class