Επεξεργασία

Κοινή χρήση μέσω


CodeDomSerializerBase.SerializeToExpression Method

Definition

Serializes the given object into an expression.

protected:
 System::CodeDom::CodeExpression ^ SerializeToExpression(System::ComponentModel::Design::Serialization::IDesignerSerializationManager ^ manager, System::Object ^ value);
protected System.CodeDom.CodeExpression SerializeToExpression (System.ComponentModel.Design.Serialization.IDesignerSerializationManager manager, object value);
protected System.CodeDom.CodeExpression? SerializeToExpression (System.ComponentModel.Design.Serialization.IDesignerSerializationManager manager, object? value);
member this.SerializeToExpression : System.ComponentModel.Design.Serialization.IDesignerSerializationManager * obj -> System.CodeDom.CodeExpression
Protected Function SerializeToExpression (manager As IDesignerSerializationManager, value As Object) As CodeExpression

Parameters

manager
IDesignerSerializationManager

The IDesignerSerializationManager to use for serialization.

value
Object

The object to serialize. Can be null.

Returns

A CodeExpression object if value can be serialized; otherwise, null.

Exceptions

manager is null.

Remarks

The value parameter can be null, in which case a primitive expression will be returned.

The SerializeToExpression method uses the following rules for serializing types:

  1. It first calls the GetExpression method to see if an expression has already been created for the object. If so, it returns the existing expression.

  2. It then locates the object's serializer, and asks it to serialize.

  3. If the return value of the object's serializer is a CodeExpression, the expression is returned.

  4. It makes one last call to GetExpression to see if the serializer added an expression.

  5. Finally, it returns null.

If no expression could be created and no suitable serializer could be found, an error will be reported through the serialization manager. No error will be reported if a serializer was found but it failed to produce an expression. In this case, it is assumed that the serializer either already reported the error or it did not attempt to serialize the object.

If the serializer returned a statement or a collection of statements, those statements will not be discarded. The SerializeToExpression method will first look for a StatementContext on the context stack and add statements to the statement context object's StatementCollection property. If there is no statement context, the SerializeToExpression method will look in the context for a CodeStatementCollection and add the statements there. If no place can be found to add the statements, an error will be generated.

Note

You should not call the SerializeToExpression method within Serialize when serializing your own object. Instead, you should call GetExpression. If it returns null, create your own expression and call SetExpression. Then proceed with the rest of your serialization.

Applies to

See also