This documentation is archived and is not being maintained.
Type.IsSerializable Property
.NET Framework 1.1
Gets a value indicating whether the Type is serializable.
[Visual Basic] Public ReadOnly Property IsSerializable As Boolean [C#] public bool IsSerializable {get;} [C++] public: __property bool get_IsSerializable(); [JScript] public function get IsSerializable() : Boolean;
Property Value
true if the Type is serializable; otherwise, false.
Example
[Visual Basic, C#, C++] The following example creates an instance of MyTestClass class, sets the [Serializable] attribute, and checks the IsSerializable property for true or false.
[Visual Basic] 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 [C#] using System; namespace SystemType { public class MyClass { // Declare a public class with the [Serializable] attribute. [Serializable] public class MyTestClass { } public static void Main(string []args) { try { bool myBool = false; MyTestClass myTestClassInstance = new MyTestClass(); // Get the type of myTestClassInstance. Type myType = myTestClassInstance.GetType(); // Get the IsSerializable property of myTestClassInstance. myBool = myType.IsSerializable; Console.WriteLine("\nIs {0} serializable? {1}.", myType.FullName, myBool.ToString()); } catch (Exception e) { Console.WriteLine("\nAn exception occurred: {0}", e.Message); } } } } [C++] #using <mscorlib.dll> using namespace System; public __gc class MyClass { // Declare a public class with the [Serializable] attribute. public: [Serializable] __gc class MyTestClass { }; }; int main() { try { bool myBool = false; MyClass::MyTestClass* myTestClassInstance = new MyClass::MyTestClass(); // Get the type of myTestClassInstance. Type* myType = myTestClassInstance->GetType(); // Get the IsSerializable property of myTestClassInstance. myBool = myType->IsSerializable; Console::WriteLine(S"\nIs {0} serializable? {1}.", myType->FullName, __box( myBool)); } catch (Exception* e) { Console::WriteLine(S"\nAn exception occurred: {0}", e->Message); } }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
See Also
Type Class | Type Members | System Namespace | TypeAttributes | ISerializable
Show: