영어로 읽기

다음을 통해 공유


Type.IsSerializable 속성

정의

주의

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

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

C#
public virtual bool IsSerializable { get; }
C#
[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; }
C#
public bool IsSerializable { get; }

속성 값

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

구현

특성

예제

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

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

설명

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

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

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

적용 대상

제품 버전 (사용되지 않음)
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7 (8, 9)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

추가 정보