Click to See Complete Forum and Search --> : CodeDomSerializer and IDesignerSerializationManager
CataHerr
May 7th, 2003, 08:06 AM
Hi
I want to create in memory a control and generate automatically the serialization code for it. I have the CodeDomSerializer-derived class, but I must pass a IDesignerSerializationManager parameter to Serialize routine. Any ideea about an existing class implementing IDesignerSerializationManager ? I searched Microsoft.VisualStudio.Designer.Serialization.CodeDomLoader, but is protected. I need only the base functionality (GetSerializer for any existing control type).
Thaks,
Catalin
pareshgh
May 7th, 2003, 07:20 PM
<MSDN SAMPLE>
[C#]
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;
}
}
}
}
</MSDN SAMPLE>
pareshgh
May 7th, 2003, 07:24 PM
also check the sample or literature for
IDesignerSerializationService (http://www.gotdotnet.com/team/windowsforms/shapedesigner.aspx)
-Paresh
CataHerr
May 8th, 2003, 01:14 AM
I know already this code. This class I implemented already. What I need is the <<IDesignerSerializationManager manager>> parameter.
Do you know how to obtain/create/use it ?
I want to create the control "on the fly" and generate the corresponding class code for it. It is just a panel containing other controls within, no additional tricks. It must be Localizable.
Thank you
Catalin
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.