This documentation is archived and is not being maintained.

Type.IsSerializable Property

Gets a value indicating whether the Type is serializable.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

'Declaration
Public ReadOnly Property IsSerializable As Boolean
'Usage
Dim instance As Type 
Dim value As Boolean 

value = instance.IsSerializable

Property Value

Type: System.Boolean
true if the Type is serializable; otherwise, false.

Implements

_Type.IsSerializable

If the current Type represents a constructed generic type, this property applies to the generic type definition from which the type was constructed. For example, if the current Type represents MyGenericType<int> (MyGenericType(Of Integer) in Visual Basic), the value of this property is determined by MyGenericType<T>.

If the current Type represents a type parameter in the definition of a generic type or generic method, this property always returns false.

The following example creates an instance of MyTestClass class, sets the [Serializable] attribute, and checks the IsSerializable property for true or false.

Imports System
Imports Microsoft.VisualBasic
Namespace SystemType
    Public Class [MyClass]
        ' Declare a public class with the [Serializable] attribute.
        <Serializable()> Public Class MyTestClass
        End Class 'MyTestClass
        Public Overloads Shared Sub Main()
            Try 
                Dim myBool As Boolean = False 
                Dim myTestClassInstance As New MyTestClass()
                ' Get the type of myTestClassInstance. 
                Dim myType As Type = myTestClassInstance.GetType()
                ' Get the IsSerializable property of myTestClassInstance.
                myBool = myType.IsSerializable
                Console.WriteLine(ControlChars.Cr + "Is {0} serializable? {1}.", myType.FullName, myBool.ToString())
            Catch e As Exception
                Console.WriteLine(ControlChars.Cr + "An exception occurred: {0}", e.Message.ToString())
            End Try 
        End Sub 'Main
    End Class '[MyClass]
End Namespace 'SystemType

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: