FieldInfo.Attributes Property gets the attributes associated with this field. : FieldInfo « Reflection « VB.Net






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

1.FieldInfo Class represents the attributes of a field and provides access to field metadata.
2.FieldInfo.FieldHandle Property gets a RuntimeFieldHandle
3.FieldInfo.FieldType Property gets the type of this field object.
4.FieldInfo.GetFieldFromHandle gets a FieldInfo for the field represented by the specified handle.
5.FieldInfo.GetFieldFromHandle
6.FieldInfo.GetValue Method returns the value of a field supported by a given object.
7.FieldInfo Get Value
8.FieldInfo.IsAssembly
9.FieldInfo.IsInitOnly Property tells whether the field can only be set in the body of the constructor.
10.FieldInfo.IsNotSerialized
11.FieldInfo.IsPinvokeImpl
12.FieldInfo.IsPrivate
13.FieldInfo.IsPublic
14.FieldInfo.IsSpecialName tells whether the SpecialName attribute is set in the FieldAttributes enumerator.
15.FieldInfo.IsStatic
16.FieldInfo.MemberType
17.FieldInfo.SetValue sets the value of the field supported by the given object.