Provides a stack object that can be used by a serializer to make information available to nested serializers.
See Also: ContextStack Members
Some serializers require information about the context of an object to correctly persist their state. The System.ComponentModel.Design.Serialization.ContextStack class enables a serializer to set data about the context of an object that is being serialized to a stack where another serializer can access it. The value of the IDesignerSerializationManager.Context property is provided by an System.ComponentModel.Design.Serialization.IDesignerSerializationManager to share information of use to some serializers.
A context stack is useful because the process of serializing a design document can be deeply nested, and objects at each level of nesting may require context information to correctly persist the state of the object. A serializer can set a context object to the stack before invoking a nested serializer. Each object set to the stack should be removed by the serializer that set it after a call to a nested serializer returns.
Typically, the objects on the stack contain information about the context of the current object that is being serialized. A parent serializer adds context information to the stack about the next object to be serialized, calls an appropriate serializer and, when the serializer finishes executing on the object, removes the context information from the stack. It is up to the implementation of each serializer to determine what objects get pushed on this stack.
As an example, an object with a property named Enabled has a data type of bool. If a serializer writes this value to a data stream, it might need to include the context or type of property it is writing. The serializer does not have this information, however, because it is only instructed to write the bool value. To provide this information to the serializer, the parent serializer can push a System.ComponentModel.PropertyDescriptor that points to the Enabled property on the context stack.