Type.IsSerializable 属性

获取一个值,通过该值指示 Type 是否为可串行的。

**命名空间:**System
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
Public ReadOnly Property IsSerializable As Boolean
用法
Dim instance As Type
Dim value As Boolean

value = instance.IsSerializable
public bool IsSerializable { get; }
public:
virtual property bool IsSerializable {
    bool get () sealed;
}
/** @property */
public final boolean get_IsSerializable ()
public final function get IsSerializable () : boolean

属性值

如果 Type 是可序列化的,则为 true;否则为 false

备注

如果当前 Type 表示某种已构造的泛型类型,则此属性适用于从中构造此类型的泛型类型定义。例如,如果当前 Type 表示 MyGenericType<int>(在 Visual Basic 中为 MyGenericType(Of Integer)),则此属性的值由 MyGenericType<T> 确定。

如果当前 Type 表示泛型类型或泛型方法的定义中的类型参数,则此属性始终返回 false

示例

下面的示例创建 MyTestClass 类的实例,设置 [Serializable] 属性 (Property),然后检查 IsSerializable 属性 (Property) 是 true 还是 false

Imports System
Imports Microsoft.VisualBasic
Namespace SystemType
    Public Class [MyClass]
        ' Declare a public class with the [Serializable] attribute.
        <Serializable()> Public Class MyTestClass
        End Class 'MyTestClass
        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 'Main
    End Class '[MyClass]
End Namespace 'SystemType
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);
            }
        }
    }
}
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 );
   }

}
package SystemType;

import System.*;

public class MyClass
{
    // Declare a public class with the [Serializable] attribute.
    /** @attribute Serializable()
     */
    public static class MyTestClass
    {
    } //MyTestClass

    public static void main(String[] args)
    {
        try {
            boolean myBool = false;
            MyTestClass myTestClassInstance = new MyTestClass();

            // Get the type of myTestClassInstance.
            Type myType = myTestClassInstance.GetType();

            // Get the IsSerializable property of myTestClassInstance.
            myBool = myType.get_IsSerializable();
            Console.WriteLine("\nIs {0} serializable? {1}.",
                myType.get_FullName(), System.Convert.ToString(myBool));
        }
        catch (System.Exception e) {
            Console.WriteLine("\nAn exception occurred: {0}", e.get_Message());
        }
    } //main
} //MyClass

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

Type 类
Type 成员
System 命名空间
TypeAttributes
ISerializable