TheChaseMan's Frenetic SoapBox

Always looking for better ways to do things...

Design by Reflector

While designing part of a .NET object model today, I was writing some code for a class indexer. One feature I thought would be cool is the ability to use a string to specify the index of my collection. My first hack at it seemed quite inefficient - loop through each object in the underlying list to match names. This would be what Joel Spolsky refers to as Shlemiel the painter's algorithm...no good. So my first thought was to use a Hashtable to relate names to objects. Then I said to myself, "self....I wonder how Microsoft does this for columns in a row for a DataSet?" So I broke out the ever-faithful Reflector tool to take a look. Here are the results...

 

public virtual DataColumn this[string name]
{
      get
      {
            DataColumn column1 = (DataColumn) this.columnFromName[name];
      }
      …
}
  
 
private Hashtable columnFromName;
 

Digg!

posted on Thursday, January 13, 2005 3:24 PM

Feedback

No comments posted yet.