I’ve not heard much about ASP.NET 4.0 yet. I don’t know if that’s because there’s not much information out there yet, or (more likely) because I haven’t been looking. We’re still very much in 2.0 land at work, so there’s not too much point getting excited about v.next features. But today I stumbled across a post on a post on an official asp.net blog called ASP.NET 4.0 ClientID Overview that details the support 4.0 will have for controlling the client-side IDs generated by server controls. Those familiar with ASP.NET will know that in current versions, all server controls that have specified IDs (thus enabling them to accessed from the code behind) generate corresponding client-side IDs containing their full naming-container hierarchy. This guarantees their uniqueness, but often means they’re very long and push up the page weight. It looks like ASP.NET 4.0 will do some work in this area to give developers more control over what IDs are generated and when, on a per control basis. Sounds pretty cool, roll-on 2015 or whenever that I can actually use this stuff in production!

Phil Haack has posted a couple of blog posts recently on named formatting in .NET. The basic idea is, instead of the usual numbered placeholders in a String.Format string like "Hello {0}, you have {1} unread messages", you have the name of properties, which are then reflected from some source object, e.g. "Hello {Name}, you have {UnreadCount} unread messages". He posted his own implementation, and a solution file containing unit-tests and a performance comparison with some alternative implementations. These posts in turn prompted a few responses from people who produced their own, even swifter implementations. So obviously, I had to have a go myself. I went for a simple, ugly, but fast approach, and at the time of writing I believe mine is the fastest (by a couple of hundredths of a second) except for one that uses some wacky Linq stuff to pre-compile property-accessing lambdas and assemble them for a particular format string. The code for mine can be found here. It’s not pretty, and I certainly wouldn’t write code like this for anything serious, but it was fun to do.






Leave a Reply

Your email address will not be published. Required fields are marked *