Check if a Type is serializable in CSharp

Description

The following code shows how to check if a Type is serializable.

Example


using System;/*  ww  w.  j  a  v  a2s.  c  o  m*/
namespace SystemType
{
    public class MyClass
    {
        [Serializable] public class MyTestClass 
        {
        }
        public static void Main(string []args)
        {
           bool myBool = false;
           MyTestClass myTestClassInstance = new MyTestClass();
           Type myType = myTestClassInstance.GetType();
           myBool = myType.IsSerializable;
           Console.WriteLine("\nIs {0} serializable? {1}.", myType.FullName, myBool.ToString());
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Reflection »




Array
Constructor
Event
Field
Interface
Method
Properties
Type