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インスタンスを作成し、[Serializable] 属性を設定し、 または falseのプロパティをIsSerializabletrueチェックします。

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 使用して、その実装が型のインスタンスのバイナリ シリアル化をサポートしているかどうかを判断できます。 詳細と例については、「 .NET Standard オブジェクトがシリアル化可能かどうかを判断する方法」を参照してください。

現在 Type の が構築されたジェネリック型を表す場合、このプロパティは、型の構築元のジェネリック型定義に適用されます。 たとえば、現在Typeの が (MyGenericType(Of Integer) を Visual Basic で表しているMyGenericType<int>場合)、このプロパティの値は によってMyGenericType<T>決定されます。

現在 Type の がジェネリック型またはジェネリック メソッドの定義で型パラメーターを表す場合、このプロパティは常に を返します false

適用対象

こちらもご覧ください