views:

386

answers:

3

To me at least, the Pair class is a very multi-purpose class. So why did Microsoft put it into the System.Web.UI namespace?

Is there a reason that my tiny brain cannot comprehend?

Thanks.

+3  A: 

It is used to serialize viewstate (along with its cousin Triplet).

I would guess that the reason they are not part of the base library (even though there is nothing ASP.NET-specific about them) is that they are not very useful since they are untyped.

To include untyped pair and triplet in the base library, might be seen as encouraging "typeless" programming.

A typed tuple might be useful, though (and I think F# has them). I think anonymous types covers most of the use cases for heterogenous tuples though.

JacquesB
I can understand why you might want to use it in a webapp, but why not make it available throughout the library? For example, why can't I use it in a basic DLL?
John MacIntyre
@John MacIntyre: You can use it in a basic DLL, you just have to include a reference to the System.Web.UI assembly.
Scott Dorman
I realize that, but if the DLL was used for a console app for example, doesn't it seem odd to have a dependency to a web ui assembly? Really shouldn't it just be in the System namespace?
John MacIntyre
Is there a Quadruplet?
Giao
@John MacIntyre: Yes, it does seem odd to have a dependency to a web ui assembly from a console app, but that's what you would need to do. Also, from @bdukes' answer, it looks like this isn't possible due to the AspNetHostingPermission LinkDemand.
Scott Dorman
@Giao - doesn't look like there is.
John MacIntyre
+3  A: 

I don't think you're going to find a great reason. It seems as though it was first created by the web team, so they made it in their namespace/assembly. They also added a LinkDemand for AspNetHostingPermission, which is unfortunate.

In terms of its "expected use," MSDN says

[The Pair class] is a utility class that is used in various ways throughout ASP.NET, such as during page state management tasks or in configuration section handlers.
...
The Pair class can be used in several ways in page state persistence implementations. The most common use is as a container for both the ViewState and ControlState collections. In this case, the First property is used for ViewState, and the Second for ControlState.

bdukes
I've always had the impression this was an after thought, something the web.ui namespace team wanted, but didn't have the ability to put it into the system namespace. It's something that's always eaten at me, and I was wondering if there is a logical reason that I couldn't see.
John MacIntyre
Silo'd development at it's worst :(
ShuggyCoUk
A: 

God forbid we should have a typed Pair that is lighter than a dictionary and can be embeeded in a typed list so that it is indexable :). Of course creating one of these is painless, but why.