Author Archives: newoldthing

What Lies Beneath Enum types

Enum types are used extensively within .NET framework to represent a group of named constant integers (default underlying type of enum elements is int) that you can use as method arguments, return values, etc; to make your program more readable and maintainable.

Once your codes are compiled into IL, all enum(s) that you use in your codes will be substituted with the underlying value. Therefore, knowing the actual values of enum elements is useful in some scenarios such as when reading the IL of a disassembled assembly.

This can be achieved easily using the reflection facility provided by .NET framework. Let say you want to see what’s inside the System.Data.DataRowState enum type, you can write and execute the following codes to list all the enum elements and the underlying integer value that each element represents:
Type dt = typeof (DataRowState);
foreach (string s in Enum.GetNames(dt))
    Console.WriteLine("{0} = {1}", s, Convert.ToInt32(
        Enum.Parse(dt, s)));

These codes will basically print the names of all members for the enum type in question, and the underlying integer values next to the names.


C# Property Access Modifier

C# property can be assigned an access modifier (public, private, protected, or internal) to control the accessibility of that property against an external caller. Prior to .NET 2.0, we could not declare a property with different access modifier for the accessor (get and set). This is somewhat limiting, considering that sometimes we want the set operation to be less public than the get operation. If you want to do that in C# 1.x, you have to do this (which is not pretty and defeats the purpose of Property syntax):

public string Name
        return name;

internal string SetName(string name)
{ = name;

Luckily, the problem was recognized and addressed in C# 2.0 with the introduction of “Asymmetric Accessor Accessibility”. So now you can do this:

public string Name
        return name;
    internal set
        name = value;

There are some restrictions for this, the most important ones being:

  • The accessor (get or set) access modifier must be more restrictive than the property access modifier.
  • Accessor modifier can only be defined when a property has both get and set accessors and the accessor modifier is only permitted on only one of the two accessors.

Just in case you’re not up to date.

Steelcase Leap It Is!

After enduring 3.5 years of poor-ergonomic chairs provided in the office and developing a pretty bad back as a result, I decided to take matter into my own hands. Enough is enough. My back is just getting worst each day and I don’t know whether I can last 8 hours on a chair by the time I’m 30 at this rate. Herman Miller Aeron chair has been pretty much my dream chair all this time, until last night I was enlightened by breathtaking design of Steelcase Leap chair. In a glimpse, Steelcase Leap looks like regular office chair, but wait until you see how adjustable it is. You can basically adjust and customize every aspect of the chair and the supports it provide: seat height, seat depth, upper back force, lower back firmness, adjustable arms, back stop, flexible seat edge, and lumbar support height. That’s something that Aeron chair won’t be able to provide in a single product.

You see, there’s something about Aeron chair that a lot of people do not know. Aeron chair comes with 3 different sizes (A, B, C). If you buy the wrong size, there’s a chance you won’t feel the maximum comfort and support that you should get from an Aeron. The size you need depends on your height and your height distribution (you know, some people are tall because they have long legs, but sometimes they’re tall because they’ve long spine). The Aeron also comes in 3 different basic configurations, the Basic Aeron (Aeron with less back support), Aeron Lumbar (lower back support), and Aeron PostureFit (best back support). If you want to upgrade from Basic to Lumbar, you need to generously add an extra $200 to your budget. Now, I already have a dilemma choosing the size, since I’ll be sharing the chair with wifey. She’s 155 cm (5’1″) tall, while I’m close to 180 cm (5’11”); which according to this chart, she’ll fit better on A-sized Aeron, while I’ll need a B-sized Aeron. Tough, either the Aeron will spoil me or her, can’t make both of us equally happy. Buying 2 Aerons will solve the problems, but I don’t plan to fund any start-up anytime soon. If getting the size is not problematic enough, how about the level of back support we need? My back is worse than hers, but she’ getting there. So what should we choose? Basic is definitely out, so it’s either Lumbar or PostureFit, which are equally pricey.

Steelcase Leap ChairSo in short, Aeron does not answer our cry for a super chair that will work best for both of us, but Leap does! Leap has one size fits all philosophy due to its superb adjustability. Leap is a result of 4 years research involving 25 scientists and 200 participants (read: human “guinea pigs”), of which testing concluded in overall of 17.8% increase in work productivity (for people who sat on Leap and received office ergonomics training). Most people who have tried both Aeron and Leap have tendency to pick Leap. The warranty is not bad too if not better than Aeron. Aeron has 12 years non-transferrable warranty if you buy from authorized dealers only. Leap has lifetime warranty for frame and structural components, 10 years for seating mechanism, and 5 years for the cushion.

All online authorized dealers charge around $799 for version 2 of this chair (you can get the version 1 for $699 or less), but I managed to find Office Environments which offers 10% instant discount on checkout; plus the online options to totally build custom Leap chair. My projection is I’ll receive this in about 2 weeks. If you’re interested in Leap, there’ll be price increase from the manufacturer on April 1st (some authorized dealers actually put this notification on their sites). I don’t think it’s a bogus marketing trick, because they’re authorized dealers.

How Does Your Browser Know that It’s Not The Default?

On Windows system, how does your browser tell that it’s currently not the default? Prior to Windows Vista, this information is stored in the registry under HKEY_CLASSES_ROOT hive, the usual place where all shell associations are kept. The default browser is maintained under HKEY_CLASSES_ROOT on per-protocol basis (as well as per file type basis, but I’m only interested in the protocols since we use browsers most of the time to access online resources, not offline). The convention for registry locations, where protocol-application associations are stored; is “HKEY_CLASSES_ROOT\[protocol]\shell\open\command “. Substitute [protocol] here with http, https, ftp, gopher or other protocols commonly supported by your favorite browser.

For example: if I want to know what is the default program for opening http protocol, then I’ll look at the registry value of “HKEY_CLASSES_ROOT\http\shell\open\command”. If I go to Start menu, click Run, type “” and then hit Enter, the URL will be opened with the application of which command line is registered in this registry value. As simple as that.

The next question will be, whether the default browser is maintained on per-user basis or it’s a system wide setting. If it’s maintained on per-user basis, then if user A set his default browser, then it will not change the default browser for user B or C. This would be somewhat the desired behavior, don’t you think? Imagine a family whose members are computer versed or so they thought, sharing one PC, and they constantly have fight over IE vs Firefox vs Opera. You don’t want the default browser to be system wide setting in that family’s PC.

But unfortunately, the answer is not straightforward. The default browser setting can be both per-user and system-wide. To understand this, you need to understand HKEY_CLASSES_ROOT hive. There’s no better place to start than MSDN documentation. In summary, there are 3 important concepts about HKEY_CLASSES_ROOT that we have to keep in mind:

  1. The HKEY_CLASSES_ROOT key provides a merged view of “HKEY_LOCAL_MACHINE\Software\Classes” (contains default settings that can apply to all users on the local computer) and “HKEY_CURRENT_USER\Software\Classes” (contains settings that apply only to the current interactive user).
  2. The user-specific settings have priority over the default settings.
  3. If you write values to a key under HKEY_CLASSES_ROOT, the values will go under:
    • HKEY_CURRENT_USER\Software\Classes; if the key exists under HKEY_CURRENT_USER\Software\Classes.
    • Otherwise, HKEY_LOCAL_MACHINE\Software\Classes.

Windows basically requires browsers to do the right thing to make the settings per-user basis instead of system-wide. In ideal scenario, before writing the default browser settings to HKEY_CLASSES_ROOT, browsers need to check if the key already exists under HKEY_CURRENT_USER or not. If the key exists there, then writing to HKEY_CLASSES_ROOT will be equal to committing to HKEY_CURRENT_USER; meaning that the settings will only affect the current interactive user and not other users. If the key doesn’t exist, then no question the key must be written under HKEY_CURRENT_USER instead of HKEY_CLASSES_ROOT. However, most (if not all) browsers basically write to HKEY_CLASSES_ROOT blindly, and since the protocol-association registrations do not exist under HKEY_CURRENT_USER by default, that means browsers write the settings to HKEY_LOCAL_MACHINE all the time. That is not only annoying and disruptive, the attempt to overwrite default browser may ultimately fail as well.

Consider the scenario of standard or limited user accounts. They don’t have write access to HKEY_LOCAL_MACHINE\Software\Classes. So if standard user says “Yes” when asked by browser X to set X as default browser, and X writes the settings to HKEY_CLASSES_ROOT which ultimately passed-through to HKEY_LOCAL_MACHINE; the registry write operation will fail. As a result, browser X will ask the same question next time it’s launched by this standard user. More frustration for the user!

Realizing these bad-eggs and with good intentions to prevent users from stepping on each other’s toes, Windows Vista introduces new way of registering default browser. It’s part of the new feature called Default Programs. It’s different to Windows XP’s SPAD (Set Program Access and Defaults) in that Default Programs is primarily controlled at the per-user level instead of per-machine level (out of the box! And does not rely on 3rd party programs to do the right thing). As part of this Default Programs, the default browser settings are now stored under “HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\ Associations\UrlAssociations\[ftp|http|https]”. Windows Vista’s shell will launch a URL with an application associated with the URL’s protocol based on the value of these registry keys. Browsers that were not aware of this change broke on Vista, they were simply unable to set itself as default browser (they saw themselves as default browser although shell didn’t think so because the twos were looking at 2 different registry keys).

Windows shell team introduced a new shell object called ApplicationAssociationRegistration to allow application registering itself as default for a particular type or protocol, as well as querying the current default. This shell object is only available on Vista, and therefore incorporating that in the code that is also targeted for previous Windows versions needs to be done with care. Tomorrow I’ll talk about how to use ApplicationAssociationRegistration shell object in a code base that is not exclusively targeted for Vista.

Gadgets Bonanza

After being clean and sober from gadgets consumerism for more than 1 year, I finally decided it’s time to go “wild” once in awhile and satisfied the craving for cutting edge goodies. Here’s the shortlist of items I managed to obtain during the past 2 months:

  • Nintendo Wii bare package (no bundled games nor accessories), which is exactly what I wanted since I can always get a deal on games and accessories whenever I feel the need to get them later. After almost 3 months of drought in Wii stocks everywhere in US market, we finally got some relief from Nintendo on mid-February. Essential accessories such as Wii Remote are still scarce as hen’s teeth, but I don’t think it will stay that way for much longer. Demands will eventually subside and consistent supply will eventually prevail. I paid USD $225 for the Wii system ($250 MSRP – 10% off deal for paying with the retailer’s card), plus some state tax for a total of around $243. Not bad, still cheaper than what most people pay these days for a Wii. I give this gizmo 5 stars out of 5 for its innovative input devices, the fun games, and the economical console price.
  • Dell 2407WFP Revision A04. In layman words, the 24″ Dell without the banding problem and with 1:1 pixel mapping. Got this with decent deal of 15% off from an already low USD $699 MSRP, plus additional 3% off for paying with Dell account, came down to total of USD $576.33 + state tax. I have to say that I agreed with Joel Spolsky; that buying from Dell was such a drain of energy for all the pre-purchase price history and discount research. Joel mentioned an irrefutable fact about Dell buying experience: “Whenever we buy servers from Dell, even though they eventually offer us a price that beats the competition, we still have to spend a week or two negotiating, gathering competitive bids, etc. By the time we place our order the price we pay is about 20% to 30% less than the price advertised on the web, and we’re still not sure if we could have paid less.” I give this beautiful and productivity booster gizmo 5 stars out of 5 (also for passing all my initial tests for new LCD monitor and the generous 3 years warranty out of the box), but I must give Dell 2 thumbs down for making purchase decision difficult with its complicated discount schemes and maze-like automated customer service call center (I was plain lucky to find the right sequence that eventually led me to speak to real person after my 3rd attempt).
  • iHome iH6 iPod speaker system/radio/alarm/digital desktop clock. In a glance, this model looks exactly the same as its older sibling, iH5. The distinctive features of iH6 over iH5 are the Shuffle dock, the equalizer, the complimentary remote iHR6 (you can purchase remote for iH5 optionally, the model is iHR5), and the 12 stations preset (8 FM + 4 AM). Snatch a decent deal from Costco warehouse for USD $89.99 (Costco’s everyday wholesale price, which is already cheaper than MSRP of iH5, USD $99.99), and with $20 manufacturer’s coupon, came down to total of USD $69.99. Not bad since the best deal I found so far for iH5 was around $50, so the $20 is definitely worth the extras.
  • Garmin Nuvi 350. Not exactly the unit I always wanted since I was targeting its successor, Nuvi 360. Both Nuvis pronounce street names and came with NAVTEQ mapping data, which is extremely important for accuracy in North America region. TomTom maybe cheaper but I’m not paying several hundred bucks just to find that I’m still lost with a GPS device that has inaccurate or out-of-date mapping data (TeleAtlas mapping data used in TomTom has strong base in Europe but not in North America unfortunately). Nuvi 360 has some nice to have features over Nuvi 350 such as Bluetooth for in car hands-free calling and Garmin lock (anti-theft feature). But for around $100 bucks less (after tax and shipping), I decided to give Nuvi 350 a go. The TCO for this very useful device is USD $350 plus tax and shipping for a total of USD $390 at
  • OEM Samsung 18x SATA DVD±RW writer and 12x DVD-RAM writer with LightScribe technology, for a nice USD $37 shipped. I’m not sure why I bought this one, I think it was just a momentary impulse since I knew the price was quite low.
  • Microsoft Wireless Entertainment Desktop 7000. I didn’t intentionally buy this Bluetooth keyboard + mouse bundle. It just happened that I visited Microsoft Company Store at Redmond and they just put this product on display for a decent price of USD $100 (MSRP is USD $150). I tried the display model and was fond of the flat, soft, and compact notebook style keys of the keyboard. It’s a pity that the keyboard is not rechargeable although the companion laser mouse is. The unreleased sibling of this model (Wireless Entertainment Desktop 8000) should have been the perfect keyboard + mouse set for me, the keyboard is rechargeable, and features a USB hub and keyboard backlight. It wasn’t meant to be…

Next on the list are the Herman Miller Aeron chair (not really a gadget, but it’s a must have for people with bad back and with the price comparable to 24″ LCD monitor…) and the bits and pieces for my desktop PC. Let’s wait and see the Intel price drop next month. I’ll update this post with some photos and more reviews later.