IDesignerSerializationManager Interface
.NET Framework 2.0
Provides an interface that can manage design-time serialization.
Namespace: System.ComponentModel.Design.Serialization
Assembly: System (in system.dll)
Assembly: System (in system.dll)
A designer can utilize IDesignerSerializationManager to access services useful to managing design-time serialization processes. For example, a class that implements the designer serialization manager can use this interface to create objects, look up types, identify objects, and customize the serialization of particular types.
The following example illustrates how to use IDesignerSerializationManager to serialize and deserialize Code DOM statements.
using System; using System.CodeDom; using System.ComponentModel; using System.ComponentModel.Design; using System.ComponentModel.Design.Serialization; using System.Drawing; using System.Windows.Forms; namespace CodeDomSerializerSample { internal class MyCodeDomSerializer : CodeDomSerializer { public override object Deserialize(IDesignerSerializationManager manager, object codeObject) { // This is how we associate the component with the serializer. CodeDomSerializer baseClassSerializer = (CodeDomSerializer)manager. GetSerializer(typeof(MyComponent).BaseType, typeof(CodeDomSerializer)); /* This is the simplest case, in which the class just calls the base class to do the work. */ return baseClassSerializer.Deserialize(manager, codeObject); } public override object Serialize(IDesignerSerializationManager manager, object value) { /* Associate the component with the serializer in the same manner as with Deserialize */ CodeDomSerializer baseClassSerializer = (CodeDomSerializer)manager. GetSerializer(typeof(MyComponent).BaseType, typeof(CodeDomSerializer)); object codeObject = baseClassSerializer.Serialize(manager, value); /* Anything could be in the codeObject. This sample operates on a CodeStatementCollection. */ if (codeObject is CodeStatementCollection) { CodeStatementCollection statements = (CodeStatementCollection)codeObject; // The code statement collection is valid, so add a comment. string commentText = "This comment was added to this object by a custom serializer."; CodeCommentStatement comment = new CodeCommentStatement(commentText); statements.Insert(0, comment); } return codeObject; } } [DesignerSerializer(typeof(MyCodeDomSerializer), typeof(CodeDomSerializer))] public class MyComponent : Component { private string localProperty = "Component Property Value"; public string LocalProperty { get { return localProperty; } set { localProperty = value; } } } }
import System.*;
import System.CodeDom.*;
import System.ComponentModel.*;
import System.ComponentModel.Design.*;
import System.ComponentModel.Design.Serialization.*;
import System.Drawing.*;
import System.Windows.Forms.*;
class MyCodeDomSerializer extends CodeDomSerializer
{
public Object Deserialize(IDesignerSerializationManager manager,
Object codeObject) {
// This is how we associate the component with the serializer.
CodeDomSerializer baseClassSerializer = (CodeDomSerializer)
manager.GetSerializer(MyComponent.class.ToType().get_BaseType(),
CodeDomSerializer.class.ToType());
/* This is the simplest case, in which the class just calls the base
class to do the work.
*/
return baseClassSerializer.Deserialize(manager, codeObject);
} //Deserialize
public Object Serialize(IDesignerSerializationManager manager,
Object value)
{
/* Associate the component with the serializer in the same manner as
with Deserialize
*/
CodeDomSerializer baseClassSerializer = (CodeDomSerializer)
manager.GetSerializer(MyComponent.class.ToType().
get_BaseType(), CodeDomSerializer.class.ToType());
Object codeObject = baseClassSerializer.Serialize(manager, value);
/* Anything could be in the codeObject. This sample operates on a
CodeStatementCollection.
*/
if (codeObject instanceof CodeStatementCollection) {
CodeStatementCollection statements = (CodeStatementCollection)
codeObject;
// The code statement collection is valid, so add a comment.
String commentText = "This comment was added to this object by a "
+ " custom serializer.";
CodeCommentStatement comment = new
CodeCommentStatement(commentText);
statements.Insert(0, comment);
}
return codeObject;
} //Serialize
} //MyCodeDomSerializer
/** @attribute DesignerSerializer(MyCodeDomSerializer.class,
CodeDomSerializer.class)
*/
public class MyComponent extends Component
{
private String localProperty = "Component Property Value";
/** @property
*/
public String get_LocalProperty()
{
return localProperty;
} //get_LocalProperty
/** @property
*/
public void set_LocalProperty (String value )
{
localProperty = value;
} //set_LocalProperty
} //MyComponent
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.