Tuesday, January 16, 2007

Today Mads shows us a not well known class that is called a Triplet. He also asks a question: how you would use it. Fortunately I have seen this class before so here is what I have learned:

Triplet is used in the same way as a Pair class - mostly in the LoadViewState and SaveViewState methods. Generally if you are saving view state in your control you not only have to store your data, but also the data returned by the call to the base.SaveViewState method. This is where the Pair class or the Triplet come in handy since given two (three) fields, one is used for the base control's state and the other can be used by your state. Similarly, when loading the state in the LoadViewState method you get your own state from one of the fields, and pass the other to the base class'es LoadViewState method. You have to remember to pass the same field you have used in the SaveViewState method or the things will go nasty ;-).

Triplet is used when Pair is not enough. If Triplet is not enough, you have to create your own class.

I hope this sheds some light on the topic.

Wednesday, January 17, 2007 9:26:01 AM (Central European Standard Time, UTC+01:00)
I would prefer to create my own type safe structure or class instead of boxing/casting objects all the time. I still don't see any reason to use this class in any of my own projects.
Wednesday, January 17, 2007 10:32:07 AM (Central European Standard Time, UTC+01:00)
True. But if you have 10 different controls for which you have to save the state, that would result in having 10 different classes. Sometimes it's not worth it to maintain such a number of classes. Sometimes though it is.
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview