Type.IsSerializable 속성

정의

주의

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

가 이진 직렬화 가능한지 여부를 Type 나타내는 값을 가져옵니다.

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

속성 값

trueType 이진 직렬화 가능하면 이고, false그렇지 않으면 입니다.

구현

특성

예제

다음 예제에서는 클래스의 MyTestClass instance 만들고 [Serializable] 특성을 설정하고 또는 false에 대한 true 속성을 확인 IsSerializable 합니다.

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

설명

.NET Standard에 정의된 형식은 로 표시되지 SerializableAttribute않습니다. 대신 각 .NET 구현은 형식이 이진 직렬화 가능한지 여부를 결정합니다. 런타임에 속성을 사용하여 해당 구현이 IsSerializable 형식의 instance 이진 serialization을 지원하는지 여부를 확인할 수 있습니다. 자세한 내용과 예제는 .NET Standard 개체를 직렬화할 수 있는지 확인하는 방법을 참조하세요.

현재 Type 가 생성된 제네릭 형식을 나타내는 경우 이 속성은 형식이 생성된 제네릭 형식 정의에 적용됩니다. 예를 들어 현재 Type 가 (Visual Basic의 경우)MyGenericType(Of Integer)를 나타내는 MyGenericType<int> 경우 이 속성의 값은 에 의해 MyGenericType<T>결정됩니다.

현재 Type 제네릭 형식 또는 제네릭 메서드의 정의에서 형식 매개 변수를 나타내는 경우 이 속성은 항상 를 반환합니다 false.

적용 대상

추가 정보