Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
This topic has not yet been rated - Rate this topic

Serialization in Managed Extensions for C++

Serialization (the process of storing the state of an object or member to a permanent medium) of managed classes (including individual fields or properties) is supported by the SerializableAttribute and NonSerializedAttribute classes. Apply the SerializableAttribute custom attribute to a managed class to serialize the entire class or apply only to specific fields or properties to serialize parts of the managed class. Use the NonSerializedAttribute custom attribute to exempt fields or properties of a managed class from being serialized.

In the following example, the __gc class MyClass (and the property m_nCount) is marked as serializable. However, the m_nData property will not be serialized as indicated by the NonSerialized custom attribute:

// serialization_and_mcpp.cpp
// compile with: /LD /clr
#using <mscorlib.dll>
using namespace System;

[ Serializable ]
public __gc class MyClass {
public:
   int m_nCount;
private:
   [ NonSerialized ]
   int m_nData;
};

Note that both attributes can be referenced using their "short name" (Serializable and NonSerialized). This is further explained in Applying Attributes.

See Also

Global Attributes and Managed Extensions for C++ | Assemblies, Attributes, and Metadata

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.