Type.IsSerializable 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
Type의 serialization 가능 여부를 나타내는 값을 가져옵니다.
public:
virtual property bool IsSerializable { bool get(); };
public:
property bool IsSerializable { bool get(); };
public virtual bool IsSerializable { get; }
public bool IsSerializable { get; }
member this.IsSerializable : bool
Public Overridable ReadOnly Property IsSerializable As Boolean
Public ReadOnly Property IsSerializable As Boolean
속성 값
Type을 serialize할 수 있으면 true이고, 그렇지 않으면 false입니다.
구현
예제
다음 예제에서는 클래스의 인스턴스 MyTestClass 를 만들고, [Serializable] 특성을 설정 하 고, IsSerializable 또는에 대 한 속성을 확인 합니다 true false .
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);
}
}
}
}
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 구현은 형식이 serialize 가능한 지 여부를 확인 합니다. 런타임에는 속성을 사용 하 여 IsSerializable 해당 구현이 형식의 인스턴스 serialization을 지원 하는지 여부를 확인할 수 있습니다. 자세한 내용 및 예제는 .NET Standard 개체를 직렬화 할 수 있는지 확인 하는 방법을 참조 하세요.
현재 Type 이 생성 된 제네릭 형식을 나타내는 경우이 속성은 형식이 생성 된 제네릭 형식 정의에 적용 됩니다. 예를 들어 현재 Type MyGenericType<int> 이 (Visual Basic)를 나타내는 경우 MyGenericType(Of Integer) 이 속성의 값은에 의해 결정 됩니다 MyGenericType<T> .
현재 Type 이 제네릭 형식 또는 제네릭 메서드 정의의 형식 매개 변수를 나타내는 경우이 속성은 항상를 반환 false 합니다.