FieldInfo::IsNotSerialized Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets a value indicating whether this field has the NotSerialized attribute.

Namespace:   System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

property bool IsNotSerialized {
	virtual bool get() sealed;

Property Value

Type: System::Boolean

true if the field has the NotSerialized attribute set; otherwise, false.

The IsNotSerialized property returns true when the field is marked with the FieldAttributes.NotSerialized flag. When this flag is set on a field, it indicates that the field does not have to be serialized when the type is remoted.

The following example gets the field information of the fields of MyClass, determines if the fields can be serialized, and displays the results.

using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::Serialization;

public ref class MyClass
   short myShort;

   // The following field will not be serialized.  

   int myInt;

int main()
   // Get the type of MyClass.
   Type^ myType = MyClass::typeid;

   // Get the fields of MyClass.
   array<FieldInfo^>^myFields = myType->GetFields( static_cast<BindingFlags>(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 ] );
            Console::WriteLine( "The {0} field is serializable.", myFields[ i ] );

.NET Framework
Available since 1.1
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top