Hi!

I've written a custom Serializer that derives from System.ComponentModel.Design.Serialization.CodeDomSerializer.
This class creates field declarations outside the InitializeComponent method with the following code:

Code Snippet

CodeTypeDeclaration pageClassCode = (CodeTypeDeclaration)manager.Context[typeof(CodeTypeDeclaration)];

if (pageClassCode != null)
{
CodeMemberField field = new CodeMemberField(type, varName);
pageClassCode.Members.Add(field);
}


That works fine, it creates for example:

Code Snippet

private MyNamespace.MyObject object1;


The rest of the code (initialization of the object and setting its properties) goes into the InitializeComponent method.

After removing the object, all code inside the InitializeComponent method is deserialized correctly (deleted in the InitializeComponent method), but the field declarations (CodeMemberFields) are not, they remain in the MainForm.Designer.cs file.

My Deserialize Method looks like the following:

Code Snippet

public override object Deserialize(IDesignerSerializationManager manager, object codeObject)
{
CodeDomSerializer baseClassSerializer = (CodeDomSerializer)manager.GetSerializer(typeof(ViewContainer).BaseType, typeof(CodeDomSerializer));
return baseClassSerializer.Deserialize(manager, codeObject);
}


Does anybody know how I can manage it to remove the field declarations outside the InitializeComponent method?

Thanks a lot in advance for your help,
Daniel