C# FieldInfo IsNotSerialized
Description
FieldInfo IsNotSerialized
Gets a value indicating whether
this field has the NotSerialized attribute.
Syntax
FieldInfo.IsNotSerialized
has the following syntax.
public bool IsNotSerialized { get; }
Example
using System;// ww w .ja v a 2 s. c om
using System.Reflection;
using System.Runtime.Serialization;
public class MyClass
{
public short myShort;
[NonSerialized()]
public int myInt;
}
public class Type_IsNotSerializable
{
public static void Main()
{
Type myType = typeof(MyClass);
FieldInfo[] myFields = myType.GetFields(BindingFlags.Public |
BindingFlags.NonPublic |
BindingFlags.Instance |
BindingFlags.Static);
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]);
}
}
The code above generates the following result.