FieldInfo.IsNotSerialized Property
.NET Framework 4
Gets a value indicating whether this field has the NotSerialized attribute.
Assembly: mscorlib (in mscorlib.dll)
Property Value
Type: System.Booleantrue if the field has the NotSerialized attribute set; otherwise, false.
Implements
_FieldInfo.IsNotSerializedThe following example gets the field information of the fields of MyClass, determines if the fields can be serialized, and displays the results.
using System; using System.Reflection; using System.Runtime.Serialization; public class MyClass { public short myShort; // The following field will not be serialized. [NonSerialized()] public int myInt; } public class Type_IsNotSerializable { public static void Main() { // Get the type of MyClass. Type myType = typeof(MyClass); // Get the fields of MyClass. FieldInfo[] myFields = myType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); Console.WriteLine("\nDisplaying whether or not the field is serializable.\n"); // Display whether or not the field is serializable. for(int i = 0; i < myFields.Length; i++) if(myFields[i].IsNotSerialized) Console.WriteLine("The {0} field is not serializable.", myFields[i]); else Console.WriteLine("The {0} field is not serializable.", myFields[i]); } }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.