Type.IsSerializable Eigenschap

Definitie

Hiermee wordt een waarde opgehaald die aangeeft of het Type binaire serializeerbaar is.

public:
 property bool IsSerializable { bool get(); };
public:
 virtual property bool IsSerializable { bool get(); };
public bool IsSerializable { get; }
public virtual bool IsSerializable { get; }
member this.IsSerializable : bool
Public ReadOnly Property IsSerializable As Boolean
Public Overridable ReadOnly Property IsSerializable As Boolean

Waarde van eigenschap

trueals het Type binair serialiseerbare is; anders. false

Implementeringen

Voorbeelden

In het volgende voorbeeld wordt een exemplaar van MyTestClass klasse gemaakt, wordt het kenmerk [Serializable] ingesteld en wordt de IsSerializable eigenschap gecontroleerd op true of false.

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);
            }
        }
    }
}
open System

// Declare a public class with the [Serializable] attribute.
[<Serializable>]
type MyTestClass() = class end

try
    let myTestClassInstance = MyTestClass()
    // Get the type of myTestClassInstance.
    let myType = myTestClassInstance.GetType()
    // Get the IsSerializable property of myTestClassInstance.
    let myBool = myType.IsSerializable
    printfn $"\nIs {myType.FullName} serializable? {myBool}."
with e ->
    printfn $"\nAn exception occurred: {e.Message}"
Namespace SystemType
    Public Class [MyClass]
        ' Declare a public class with the [Serializable] attribute.
        <Serializable()> Public Class MyTestClass
        End Class
        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
    End Class
End Namespace 'SystemType

Opmerkingen

Typen die zijn gedefinieerd in de .NET Standard, worden niet gemarkeerd met SerializableAttribute. In plaats daarvan bepaalt elke .NET implementatie of een type binair serialiseerbaar is. Tijdens runtime kunt u de IsSerializable eigenschap gebruiken om te bepalen of die implementatie binaire serialisatie van een exemplaar van het type ondersteunt. Zie Hoe u kunt bepalen of een .NET Standaardobject serialiseerbaar is voor meer informatie en een voorbeeld.

Als de huidige Type een samengesteld algemeen type vertegenwoordigt, is deze eigenschap van toepassing op de algemene typedefinitie van waaruit het type is samengesteld. Als de huidige Type bijvoorbeeld MyGenericType<int> (MyGenericType(Of Integer) in Visual Basic) vertegenwoordigt), wordt de waarde van deze eigenschap bepaald door MyGenericType<T>.

Als de huidige Type een typeparameter vertegenwoordigt in de definitie van een algemeen type of algemene methode, retourneert falsedeze eigenschap altijd .

Van toepassing op

Zie ook