Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

CodeDomSerializerBase.SerializeToExpression Method

Serializes the given object into an expression.

Namespace:  System.ComponentModel.Design.Serialization
Assembly:  System.Design (in System.Design.dll)

protected CodeExpression SerializeToExpression(
	IDesignerSerializationManager manager,
	Object value
)

Parameters

manager
Type: System.ComponentModel.Design.Serialization.IDesignerSerializationManager

The IDesignerSerializationManager to use for serialization.

value
Type: System.Object

The object to serialize. Can be null.

Return Value

Type: System.CodeDom.CodeExpression
A CodeExpression object if value can be serialized; otherwise, null.

ExceptionCondition
ArgumentNullException

manager is null.

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.

NoteNote

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.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0
Show:
© 2015 Microsoft