This post originated from an RSS feed registered with .NET Buzz
by Udi Dahan.
Original Post: Switch statement angst
Feed Title: Udi Dahan - The Software Simplist
Feed URL: http://feeds.feedburner.com/UdiDahan-TheSoftwareSimplist
Feed Description: I am a software simplist. I make this beast of architecting, analysing, designing, developing, testing, managing, deploying software systems simple.
This blog is about how I do it.
The C# compiler doesn't like the following code:
public void NewCommandActivatedCallback(object sender, EntityTypeEventArgs e);
{
switch(e.EntityType)
{
case typeof(Customer): // open new customer form; break;
case typeof(Order): // open new order form; break;
//and so on
}
}
It doesn't like the fact that the values of the case elements aren't constant. Well, logically speaking they are constant. Is the following code that much different?
public void NewCommandActivatedCallback(object sender, EntityTypeEventArgs e);
{
switch(e.EntityType.Name)
{
case "Customer": // open new customer form; break;
case "Order": // open new order form; break;
//and so on
}
}
Well, yes. For starters, it compiles. It's also uglier. And less maintainable. But, its semantically equivalent.
My wish for Orcas is FIX IT!!! God! We've been carrying this crap through 2.5 versions of .net. Enough already. Hell, roll it into SP1 of VS2003 or VS2005. It's not like it'll break any existing code.
OK, I feel better now. Move along now. Nothing to see here.