Type.IsSerializable Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Obtém um valor que indica se o Type é binariamente serializável.
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
Valor de Propriedade
true se o Type for binariamente serializável; caso contrário, false.
Implementações
Exemplos
O exemplo seguinte cria uma instância de MyTestClass class, define o atributo [Serializable] e verifica a IsSerializable propriedade para true ou 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
Observações
Os tipos definidos na .NET Standard não estão marcados com SerializableAttribute. Em vez disso, cada implementação .NET determina se um tipo é binariamente serializável. Em tempo de execução, pode usar a IsSerializable propriedade para determinar se essa implementação suporta serialização binária de uma instância do tipo. Para mais informações e um exemplo, veja Como determinar se um objeto .NET Standard é serializável.
Se a corrente Type representa um tipo genérico construído, esta propriedade aplica-se à definição genérica de tipo a partir da qual o tipo foi construído. Por exemplo, se o atual Type representa MyGenericType<int> (MyGenericType(Of Integer) em Visual Basic), o valor desta propriedade é determinado por MyGenericType<T>.
Se a corrente Type representa um parâmetro de tipo na definição de um tipo genérico ou método genérico, esta propriedade devolve falsesempre .