Type.IsSerializable Özellik

Tanım

Dikkat

Formatter-based serialization is obsolete and should not be used.

ikili serileştirilebilir olup olmadığını Type belirten bir değer alır.

public:
 virtual property bool IsSerializable { bool get(); };
public:
 property bool IsSerializable { bool get(); };
public virtual bool IsSerializable { get; }
[System.Obsolete("Formatter-based serialization is obsolete and should not be used.", DiagnosticId="SYSLIB0050", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public virtual bool IsSerializable { get; }
public bool IsSerializable { get; }
member this.IsSerializable : bool
[<System.Obsolete("Formatter-based serialization is obsolete and should not be used.", DiagnosticId="SYSLIB0050", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
member this.IsSerializable : bool
Public Overridable ReadOnly Property IsSerializable As Boolean
Public ReadOnly Property IsSerializable As Boolean

Özellik Değeri

trueType ikili serileştirilebilirse; değilse, false.

Uygulamalar

Öznitelikler

Örnekler

Aşağıdaki örnek bir sınıf örneği MyTestClass oluşturur, [Serializable] özniteliğini ayarlar ve veya falseiçin true özelliğini denetlerIsSerializable.

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

}
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

Açıklamalar

.NET Standard'da tanımlanan türler ile SerializableAttributeişaretlenmez. Bunun yerine, her .NET uygulaması bir türün ikili serileştirilebilir olup olmadığını belirler. Çalışma zamanında, bu uygulamanın türün IsSerializable bir örneğinin ikili serileştirmesini destekleyip desteklemediğini belirlemek için özelliğini kullanabilirsiniz. Daha fazla bilgi ve örnek için bkz. .NET Standard nesnesinin seri hale getirilebilir olup olmadığını belirleme.

Geçerli Type , yapılı bir genel türü temsil ederse, bu özellik türün oluşturulduğu genel tür tanımına uygulanır. Örneğin, geçerli Type değeri (MyGenericType(Of Integer) Visual Basic'te) temsil ederse MyGenericType<int> , bu özelliğin değeri tarafından MyGenericType<T>belirlenir.

Geçerli Type , genel bir türün veya genel yöntemin tanımındaki bir tür parametresini temsil ederse, bu özellik her zaman döndürür false.

Şunlara uygulanır

Ayrıca bkz.