net comments edit

I’m working on a DataGridColumn that can automatically sum up the data in the column and display a total of the data in the footer. This sort of thing comes in handy when displaying tables with account activity or balance data in them and allows you to just put the special column type right into the DataGrid without having to modify your page behavior to do the summation.

So I created my column class have it set up so when the column is databound, each cell in the column will contribute its bound value toward a total. That’s where I ran into a snag - since I don’t know what object type is being bound to the column, my “total” variable is just an object… and base objects don’t support addition.

How do you tell if an object type supports addition?

That’s actually something I can’t answer. My original thought was that when you override the addition operator, the compiler generates a static “Add” method for your data type. You can see this in Reflector. Here’s the System.Decimal class:

System.Decimal supports the Add
method.

Notice there’s a static method called “Add” that takes in two System.Decimal objects and returns a System.Decimal object. That’s what you see when you override the addition operation.

My idea was that I would get the first object being bound to the column, get its type, and see if it had a static method called “Add” that takes in two objects of that type and returns an object of that type. If that method exists, I’ll hold a reference to it and invoke it for every subsequent data item being added.

The problem is, this static “Add” method doesn’t show up for other base types. For example, there’s no “Add” method for System.Int32:

System.Int32 has no Add
method.

So that idea won’t work.

I talked to Hanselman and Sells and they both thought the “Add” method would be there. No such luck.

Right now I’m working around it by special casing all of the types in mscorlib that I know we use that can be added together… but is there some better way I can, through Reflection, determine if two objects can be added (and then actually perform that addition)?

It’s been a heck of a busy week, so I haven’t had a chance to blog about the wedding I went to this past weekend.

Saturday Jenn and I packed up and headed to Puyallup, WA, to see my cousin Haley get married. The ceremony was at High Cedars Golf Club. It was a nice ceremony, though the minister seemed a little frazzled like he had never performed a marriage ceremony before. Regardless, congratulations to Haley and Adam Horton.

Immediately following the wedding there was a minor incident involving Adam running over Haley’s dress with a golf cart and ripping the back on it, but a few safety pins later and Adam’s first married-life “I’m sorry,” everything was back in order.

The real excitement came when we checked into our hotel up there. We stayed at the Crossland Economy Studios up there because we knew the wedding would go reasonably late and we didn’t want to drive the three hours back that night.

When we made the reservation, they offered us our choice of a room with two double beds or a room with two queen beds. A double’s a little small, so I picked the room with two queens. When we got there, they told me the hotel was packed, so rather than getting one room with two beds, they had me in two rooms, each with one bed, where each room would only cost me half price. Not needing two beds, I told the clerk I only needed one of the rooms. The cool part - I got to keep the half price. So I stayed there for $35, including tax.

The not so cool part - the bed was a freaking double. Oh, and the mattress was firm, sort of in the sense that a sheet of plywood laying on cement is firm. But, hey, $35, right?

We had a decent drive home the next day (though the trip south on I-5 is one of the most boring drives ever) and spent most of the day Sunday lounging on the couch, exhausted.

GeekSpeak comments edit

Eli Lopian from TypeMock has blogged the case study we did with TypeMock showing how much more productive we are in testing using TypeMock.

We’ve been vastly more productive using TypeMock than we were before we adopted it. If you get a chance, check out the Case Study PDF. It pretty much says it all. And if you haven’t tried TypeMock yet, what are you waiting for? Go get it. You’ll like it, I promise.

(In the interest of shameless-self-promotion full disclosure, I’m fairly prominently quoted in the case study. I can’t lie; it makes me smile. Can’t help but love TypeMock.)