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.