Type.IsSerializable-Eigenschaft
Ruft einen Wert ab, der angibt, ob Type serialisierbar ist.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public ReadOnly Property IsSerializable As Boolean
'Usage
Dim instance As Type
Dim value As Boolean
value = instance.IsSerializable
public bool IsSerializable { get; }
public:
virtual property bool IsSerializable {
bool get () sealed;
}
/** @property */
public final boolean get_IsSerializable ()
public final function get IsSerializable () : boolean
Eigenschaftenwert
true, wenn Type serialisierbar ist, andernfalls false.
Hinweise
Wenn der aktuelle Type einen konstruierten generischen Typ darstellt, gilt diese Eigenschaft für die generische Typdefinition, aus der der Typ konstruiert wurde. Wenn z. B. der aktuelle TypeMyGenericType<int>
darstellt (MyGenericType(Of Integer)
in Visual Basic), wird der Wert dieser Eigenschaft durch MyGenericType<T>
bestimmt.
Wenn der aktuelle Type einen Typparameter in der Definition eines generischen Typs oder einer generischen Methoden darstellt, gibt diese Eigenschaft immer false zurück.
Beispiel
Im folgenden Beispiel wird eine Instanz der MyTestClass-Klasse erstellt, das [Serializable]-Attribut festgelegt und die IsSerializable-Eigenschaft auf true oder false überprüft.
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
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);
}
}
}
}
using namespace System;
public ref class MyClass
{
public:
// Declare a public class with the [Serializable] attribute.
[Serializable]
ref class MyTestClass{};
};
int main()
{
try
{
bool myBool = false;
MyClass::MyTestClass^ myTestClassInstance = gcnew MyClass::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 );
}
catch ( Exception^ e )
{
Console::WriteLine( "\nAn exception occurred: {0}", e->Message );
}
}
package SystemType;
import System.*;
public class MyClass
{
// Declare a public class with the [Serializable] attribute.
/** @attribute Serializable()
*/
public static class MyTestClass
{
} //MyTestClass
public static void main(String[] args)
{
try {
boolean myBool = false;
MyTestClass myTestClassInstance = new MyTestClass();
// Get the type of myTestClassInstance.
Type myType = myTestClassInstance.GetType();
// Get the IsSerializable property of myTestClassInstance.
myBool = myType.get_IsSerializable();
Console.WriteLine("\nIs {0} serializable? {1}.",
myType.get_FullName(), System.Convert.ToString(myBool));
}
catch (System.Exception e) {
Console.WriteLine("\nAn exception occurred: {0}", e.get_Message());
}
} //main
} //MyClass
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
Type-Klasse
Type-Member
System-Namespace
TypeAttributes
ISerializable