FieldInfo.Attributes Property gets the attributes associated with this field.
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
Public Class Demo
Private m_field As String = "String A"
Public Field As String = "String B"
Public Const FieldC As String = "String C"
End Class
Module Module1
Sub Main()
Dim d As New Demo()
Dim myType As Type = GetType(Demo)
Dim fiPrivate As FieldInfo = myType.GetField("m_field", BindingFlags.NonPublic Or BindingFlags.Instance)
DisplayField(d, fiPrivate)
Dim fiPublic As FieldInfo = myType.GetField("Field", BindingFlags.Public Or BindingFlags.Instance)
DisplayField(d, fiPublic)
Dim fiConstant As FieldInfo = myType.GetField("FieldC", BindingFlags.Public Or BindingFlags.Static)
DisplayField(d, fiConstant)
End Sub
Sub DisplayField(ByVal obj As Object, ByVal f As FieldInfo)
Console.WriteLine(f.Name)
Console.WriteLine(f.GetValue(obj))
Console.WriteLine(f.Attributes)
End Sub
End Module
Related examples in the same category