FieldInfo.IsNotSerialized
Imports System
Imports System.Reflection
Imports System.Runtime.Serialization
Imports Microsoft.VisualBasic
<Serializable()> _
Public Class [MyClass]
Public myShort As Short
<NonSerialized()> Public myInt As Integer
End Class '[MyClass]
Public Class Type_IsNotSerializable
Public Shared Sub Main()
Dim myType As Type = GetType([MyClass])
Dim myFields As FieldInfo() = myType.GetFields((BindingFlags.Public Or BindingFlags.NonPublic Or BindingFlags.Instance Or BindingFlags.Static))
Dim i As Integer
For i = 0 To myFields.Length - 1
If myFields(i).IsNotSerialized Then
Console.WriteLine("The {0} field is not serializable.", myFields(i))
Else
Console.WriteLine("The {0} field is serializable.", myFields(i))
End If
Next i
End Sub
End Class
Related examples in the same category