FieldInfo.IsInitOnly Property tells whether the field can only be set in the body of the constructor. : FieldInfo « Reflection « VB.Net






FieldInfo.IsInitOnly Property tells whether the field can only be set in the body of the constructor.

 
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic

Public Class Myfielda
    Public field As String = "public modifiable field"
End Class 'Myfielda

Public Class Myfieldb
    Public ReadOnly field As String = "readonly field"
End Class 'Myfieldb

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("field",BindingFlags.Public Or BindingFlags.Instance)
        Dim MyTypeb As Type = GetType(Myfieldb)
        Dim Myfieldinfob As FieldInfo = MyTypeb.GetField("field",BindingFlags.Public Or BindingFlags.Instance)

        Myfielda.field = "A - modified"
        Console.WriteLine(MyTypea.FullName)
        Console.WriteLine(Myfieldinfoa.GetValue(Myfielda))
        Console.WriteLine(Myfieldinfoa.IsInitOnly)
        Console.WriteLine(MyTypeb.FullName)
        Console.WriteLine(Myfieldinfob.GetValue(Myfieldb))
        Console.WriteLine(Myfieldinfob.IsInitOnly)

        Return 0
    End Function 'Main
End Class 'Myfieldinfo

   
  








Related examples in the same category

1.FieldInfo Class represents the attributes of a field and provides access to field metadata.
2.FieldInfo.Attributes Property gets the attributes associated with this field.
3.FieldInfo.FieldHandle Property gets a RuntimeFieldHandle
4.FieldInfo.FieldType Property gets the type of this field object.
5.FieldInfo.GetFieldFromHandle gets a FieldInfo for the field represented by the specified handle.
6.FieldInfo.GetFieldFromHandle
7.FieldInfo.GetValue Method returns the value of a field supported by a given object.
8.FieldInfo Get Value
9.FieldInfo.IsAssembly
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.