TypeCodeDomSerializer.Serialize Method

Definition

Serializes the object root by creating a new type declaration that defines root.

public:
 virtual System::CodeDom::CodeTypeDeclaration ^ Serialize(System::ComponentModel::Design::Serialization::IDesignerSerializationManager ^ manager, System::Object ^ root, System::Collections::ICollection ^ members);
public virtual System.CodeDom.CodeTypeDeclaration Serialize (System.ComponentModel.Design.Serialization.IDesignerSerializationManager manager, object root, System.Collections.ICollection members);
public virtual System.CodeDom.CodeTypeDeclaration Serialize (System.ComponentModel.Design.Serialization.IDesignerSerializationManager manager, object root, System.Collections.ICollection? members);
abstract member Serialize : System.ComponentModel.Design.Serialization.IDesignerSerializationManager * obj * System.Collections.ICollection -> System.CodeDom.CodeTypeDeclaration
override this.Serialize : System.ComponentModel.Design.Serialization.IDesignerSerializationManager * obj * System.Collections.ICollection -> System.CodeDom.CodeTypeDeclaration
Public Overridable Function Serialize (manager As IDesignerSerializationManager, root As Object, members As ICollection) As CodeTypeDeclaration

Parameters

manager
IDesignerSerializationManager

The serialization manager to use for serialization.

root
Object

The object to serialize.

members
ICollection

Optional collection of members. Can be null or empty.

Returns

A CodeTypeDeclaration that defines the root object.

Exceptions

manager or root is null.

Remarks

The Serialize method serializes the given root object and optional collection of members to create a new type definition. If the members collection contains values, these values are serialized. Values themselves may serialize as either member variables or local variables. This determination is done by searching for an extender property on the object called GenerateMember. If true, a member is generated. Otherwise, a local variable is generated. For convenience, the members collection can contain the root object. In this case, the root object is not also added as a member or local variable.

The name of the returned type is taken from the root object's name, if it was a named object. If not, a name is fabricated from the simple type name of the root class.

The following table shows the tasks performed by the default implementation of the Serialize method.

Task Description
Context Seeding The serialization context is initialized with data including the RootContext and CodeTypeDeclaration
Member Serialization Next, Serialize walks all of the members and calls SerializeToExpression. Because serialization is done opportunistically in SerializeToExpression, this ensures that serialization is not done twice.
Root Serialization Next, the root object is serialized and its statements are added to the statement collection.
Statement Integration After all objects are serialized, the Serialize method orders the statements and adds them to a method returned from GetInitializeMethod. Finally, a constructor is fabricated that calls all of the methods returned from GetInitializeMethod.

-

The following table shows the objects the Serialize method places on the context stack.

Instance Description
TypeCodeDomSerializer This serializer. Deriving classes may find it useful to add public properties to this class.
CodeTypeDeclaration The type being created. Most objects do not need direct access to this.

Applies to

See also