By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,203 Members | 1,646 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,203 IT Pros & Developers. It's quick & easy.

Serialization to ViewState -- when are TypeConverters required?

P: n/a
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 :-)
Nov 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.