FieldInfo.IsPrivate
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
Class [MyClass]
Private myField As String
Public myArray() As String = {"A", "B"}
Sub New()
myField = "AAA"
End Sub 'New
ReadOnly Property GetField() As String
Get
Return myField
End Get
End Property
End Class '[MyClass]
Class FieldInfo_IsPrivate
Public Shared Sub Main()
Try
Dim myType As Type = GetType([MyClass])
Dim myFields As FieldInfo() = myType.GetFields((BindingFlags.NonPublic Or BindingFlags.Public Or BindingFlags.Instance))
Console.WriteLine(myType)
Dim i As Integer
For i = 0 To myFields.Length - 1
If myFields(i).IsPrivate Then
Console.WriteLine("{0} is a private field.", myFields(i).Name)
Else
Console.WriteLine("{0} is not a private field.", myFields(i).Name)
End If
Next i
Catch e As Exception
Console.WriteLine("Exception : {0} ", e.Message.ToString())
End Try
End Sub
End Class
Related examples in the same category