C# Type IsSerializable

Description

Type IsSerializable gets a value indicating whether the Type is serializable.

Syntax

Type.IsSerializable has the following syntax.


public virtual bool IsSerializable { get; }

Example

The following example creates an instance of MyTestClass class, sets the [Serializable] attribute, and checks the IsSerializable property for true or false.


using System;//from ww w. j av a 2  s  .  c  o m
namespace SystemType
{
    public class MyClass
    {
        [Serializable] public class MyTestClass 
        {
        }
        public static void Main(string []args)
        {
            try
            {
                bool myBool = false;
                MyTestClass myTestClassInstance = new MyTestClass();
                Type myType = myTestClassInstance.GetType();
                Console.WriteLine(myType.IsSerializable);
            }
            catch (Exception e)
            {
                Console.WriteLine("\nAn exception occurred: {0}", e.Message);
            }
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version