Serialization to ViewState -- when are TypeConverters required?

S

S.Sigal

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 :)
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top