CodeDomSerializer and Design time code generation

Discussion in 'ASP .Net' started by onyxring, Feb 12, 2006.

  1. onyxring

    onyxring Guest

    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
    onyxring, Feb 12, 2006
    #1
    1. Advertising

  2. onyxring

    onyxring Guest

    > 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;
    }
    }
    }
    onyxring, Feb 13, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Frank
    Replies:
    1
    Views:
    483
    Roedy Green
    Aug 28, 2003
  2. Carlo v. Dango

    run time code generation in python

    Carlo v. Dango, Oct 9, 2003, in forum: Python
    Replies:
    6
    Views:
    366
    Bengt Richter
    Oct 12, 2003
  3. flamesrock
    Replies:
    8
    Views:
    435
    Hendrik van Rooyen
    Nov 24, 2006
  4. Björn Marthen

    CodeDomSerializer

    Björn Marthen, Nov 10, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    107
    IgorW
    Nov 13, 2003
  5. John W. Long

    HTML Generation (Next Generation CGI)

    John W. Long, Nov 22, 2003, in forum: Ruby
    Replies:
    4
    Views:
    317
    John W. Long
    Nov 24, 2003
Loading...

Share This Page