Serialization to ViewState -- when are TypeConverters required?

Discussion in 'ASP .Net' started by S.Sigal, Aug 21, 2004.

  1. S.Sigal

    S.Sigal Guest

    Hello:

    I've been trying to 'organize' the layout of my larger controls by moving variables into instances
    of subclasses...but it just dawned on me that I might be opening a real can of worms due to StateBag
    serialization...

    If ViewState serialization is optimized for Int32, Bool, String, Color, and arrays thereof... what
    happens when I want to serialize the instance of a class that contains an Int32, Bool String, or
    Color?

    In other words, if this is optimized:

    class MyControl : WebControl {
    public Int Uno {get {object o = ViewState['Int'];return (o==null)?0:(int)o);}set
    {ViewState["Int"] = value;}}
    public string Dos{get {object o = ViewState['S'];return (o==null)?0:(string)o);}set
    {ViewState["S"] = value;}}
    public bool Dos{get {object o = ViewState['B'];return (o==null)?0:(bool)o);}set {ViewState["B"]
    = value;}}
    ....
    }

    ...is the following optimized as well -- by proxy -- or does it totally mess up everything and fall
    back to the lowest common denominator of BinarySerialization or something?


    class MyControl : WebControl {
    public Control_Grouped_Vars Vars {get {return _Vars;}}
    private Control_Grouped_Vars _Vars = new Control_Grouped_Vars();
    ....
    override LoadViewState...
    override SaveViewState...
    }

    public class Control_Grouped_Vars : IStateManaged {
    public Int Uno {get {object o = ViewState['Int'];return (o==null)?0:(int)o);}set
    {ViewState["Int"] = value;}}
    public string Dos{get {object o = ViewState['S'];return (o==null)?0:(string)o);}set
    {ViewState["S"] = value;}}
    public bool Dos{get {object o = ViewState['B'];return (o==null)?0:(bool)o);}set {ViewState["B"]
    = value;}}
    override LoadViewState...
    override SaveViewState...
    }





    Questions would be:
    a) No need to worry?
    b) If yes, will a custom TypeConverter do the trick? Convert the public props to a string of
    key:value;key:Value; (same as html style attribute) do the trick?





    Thanks for getting back to me asap before I do a lot of damage to myself :)
     
    S.Sigal, Aug 21, 2004
    #1
    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. Replies:
    8
    Views:
    2,258
    deadsea
    Jan 2, 2005
  2. Replies:
    3
    Views:
    1,040
  3. Dimitri Ognibene
    Replies:
    4
    Views:
    786
    Dimitri Ognibene
    Sep 2, 2006
  4. David Jessee

    Using TypeConverters

    David Jessee, Jul 14, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    104
    Teemu Keiski
    Jul 14, 2003
  5. MLibby

    TypeConverters

    MLibby, Sep 30, 2004, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    102
    Jeffrey Tan[MSFT]
    Oct 7, 2004
Loading...

Share This Page