Practicality of having typed view state/ViewState API for ASP.NET 2.0?
I’m quite sure someone has brought this up at some point either theoretically or jokingly, and I’m not sure how feasible it would be (although I think it would be pretty cool), but can/should a page’s view state be able to be typed, rather than just storing all data within as type object?
Perhaps the convention of - ViewState[“key”] - could include a second argument when 2.0 rolls out, which would be the explicitly-stated data type for the data?
CHEESY EXAMPLE 1:
String myName = “Jason Salas”;
ViewState[“aDudeInGuam”,System.String] = myName;
Or, possibly this could be set in web.config for **certain** ViewState entries, providing typing information, as the Profile does object for personalization in 2.0?
CHEESY EXAMPLE 2:
<viewstate keyName=“phoneNumber“ type=“System.Int32“/>
Or, maybe include a ViewState API (there’s a thought), similar to what is provided with the Cache API, wherein developers have a variety of overloaded methods from which to choose in setting/accessing view state values?
CHEESY EXAMPLE 3:
int homePhoneJenny = 8675309;
ViewState.Insert(“keyPhone”, homePhoneJenny,System.Int32);
Would this even be worth it, or make sense? It seems to me like this would fit in nicely with Whidbey’s push towards more streamlined programming without the need for casting/recasting data.
Certainly, many people would get something out of it when working with business logic, and if this would help improve the expensive performance hit caused by the Framework's internal binary serialization for types without readily-available type converters, that would be gravy.
What do you think?