CodeDomSerializer and Design time code generation

O

onyxring

I've been building custom web controls in C# with VS2005. Currently I'm
looking into adding design-time functionality and have reached a point where
I need to generate code in the page the custom control is on. Enter the
CodeDomSerializer class.



I've found several examples creating Designer Serializers, nearly all of
them for windows forms, but a few claiming to work for Web Controls;
however, I have been singularly unsuccessful at every attempt to modify
source code during the design-time experience. Clearly I'm doing something
wrong, but what it is escapes me.



Below is a sample of the technique I've been using, scaled down to the
barest minimum and excluding designers and other things you might expect for
a custom control. It appears to me that this should work, though adding this
"newtest" control to a page clearly does not add the comment expected.



Can anyone add some clarity at to what I'm doing wrong? Thank you in
advance.



-Jim Fisher
 
O

onyxring

Below is a sample of the technique I've been using, scaled down to the
barest minimum and excluding designers and other things you might expect
for a custom control.

Um... here's the sample (sorry):
namespace testcontrol {
[DesignerSerializer(typeof(newtest_serializer),
typeof(CodeDomSerializer))]
public partial class newtest : System.Web.UI.WebControls.TextBox {
public newtest() {
InitializeComponent();
}
public newtest(IContainer container) {
container.Add(this);
InitializeComponent();
}
}
internal class newtest_serializer : CodeDomSerializer {
public override object Deserialize(IDesignerSerializationManager
manager, object codeObject) {
CodeDomSerializer serial =
(CodeDomSerializer)manager.GetSerializer(typeof(newtest).BaseType,
typeof(CodeDomSerializer));
return serial.Deserialize(manager,codeObject);
}
public override object Serialize(IDesignerSerializationManager
manager, object value) {
CodeDomSerializer serial =
(CodeDomSerializer)manager.GetSerializer(typeof(newtest).BaseType,
typeof(CodeDomSerializer));
CodeStatementCollection statements =
(CodeStatementCollection)serial.Serialize(manager, value);
statements.Add(new CodeCommentStatement("//--------
CodingComment--------"));
return statements;
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top