FieldInfo.IsPublic
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
Public Class Myfielda
Private SomeField As String = "private field"
Public ReadOnly Property Field() As String
Get
Return SomeField
End Get
End Property
End Class 'Myfielda
Public Class Myfieldb
Public SomeField As String = "public field"
End Class
Public Class Myfieldinfo
Public Shared Function Main() As Integer
Dim Myfielda As New Myfielda()
Dim Myfieldb As New Myfieldb()
Dim MyTypea As Type = GetType(Myfielda)
Dim Myfieldinfoa As FieldInfo = MyTypea.GetField("SomeField",BindingFlags.NonPublic Or BindingFlags.Instance)
Dim MyTypeb As Type = GetType(Myfieldb)
Dim Myfieldinfob As FieldInfo = MyTypeb.GetField("SomeField")
Console.WriteLine("{0}.{1} - {2}", MyTypea.FullName, Myfieldinfoa.Name,Myfielda.Field)
Console.WriteLine(" IsPublic = {0}", Myfieldinfoa.IsPublic)
Console.WriteLine(" IsPrivate = {0}", Myfieldinfoa.IsPrivate)
Console.WriteLine()
Console.WriteLine("{0}.{1} - {2}", MyTypeb.FullName, Myfieldinfob.Name,Myfieldb.SomeField)
Console.WriteLine(" IsPublic = {0}", Myfieldinfob.IsPublic)
Console.WriteLine(" IsPrivate = {0}", Myfieldinfob.IsPrivate)
Return 0
End Function 'Main
End Class 'Myfieldinfo
Related examples in the same category