# Tuesday, March 13, 2007
I ended up modifying my reusable IComparer class to work on any data type that implements IComparable since our data grid now has a decimal data type for one the columns.  I'm now betting that the users will want/need to be able to sort ascending and descending, not just ascending.  Also case insensitive comparisons will probably be required (although my original implementation did have this).

Perhaps its time I Googled a more mature implementation up, CodeProject must have one already.

Tuesday, March 13, 2007 6:58:13 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Saturday, March 10, 2007
Right now I'm refactoring an ASP.NET 1.1 application that another team member wrote not too long ago.  When I took it over there were 6 unit tests (4 working ones), but really they weren't true unit tests because the code that went into production was never getting tested.  They weren't really testing anything except for the special case code that only ran when under test.

if (m_testingData)
{
   serviceResults = m_testingData;
}
else
{
   RequestorDataService ds = new RequestorDataService(m_url);
   ds.Message = CreateSOAPRequest();
   ds.Submit();
   serviceResults = ds.GetResults();
}

Does anyone see a problem with the above code fragment?  Some IoC love would go a long way here.

Testing | WTF
Saturday, March 10, 2007 8:55:23 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [2]  | 
I needed to implement sorting in one of our applications that contained a grid with multiple properties.  Normally in .NET 1.1 most people would throw the data into a DataSet and be on their way, but I already had a domain model with some nice POCOs, so I though why bother to load a dataset just to support sorting on a few elements?  I started to write a an IComparer but then I realized I would have to do it 6 more times for each property.  No thanks.

I decided to implement a super easy string property comparer that would get the property it needed to compare using reflection.

/// <summary>
/// Generic and reusable IComparer for string based properties.
/// </summary>
public class StringPropertyComparer : IComparer
{
    private string m_propertyName;
    private Type m_declaringClass;

    public StringPropertyComparer(Type declaringClass, string propertyName)
    {
        m_declaringClass = declaringClass;
        m_propertyName = propertyName;
    }

    private string getPropertyValue(object instance)
    {
        PropertyInfo info = m_declaringClass.GetProperty(m_propertyName, typeof(string));
        return (string) info.GetValue(instance, null);
    }

    public int Compare(object lhsObj, object rhsObj)
    {
        string lhs = getPropertyValue(lhsObj);
        string rhs = getPropertyValue(rhsObj);

        return ((new CaseInsensitiveComparer()).Compare(lhs, rhs));
    }
}

This could really be expanded to support multiple types besides strings, support asc and desc, and to support ordering by n+1 properties.  Perhaps some other day...  This works for now.


Saturday, March 10, 2007 12:27:41 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Wednesday, March 07, 2007
Sometimes it's the simple things that make you go wow!  I just ran into one of those today while reading up on better HTML/CSS usage, I found there's an HTML element just for providing labels for input control.

Here's an example:

<label for="loanNumber">Loan Number</label>
<input id="loanNumber" type="text"/>



Not only does this render side by side, but its more obvious and provides semantic meaning.  Another cool thing is that when you click on the label text in your browser, then input control associated with becomes activated, try it!


Wednesday, March 07, 2007 10:43:32 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [1]  | 
So I finally added an about me section.  It uses DasBlog URL rewriting and FormatPage.aspx.

Wednesday, March 07, 2007 8:15:20 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
How can you have an invalid enum?  Why would you want an invalid enum?  I know it seems almost contradictory to have an invalid enum, but I have run into the situation once or twice.  Usually its where there is a switch statement that does some particular action based off an enum and in that switch statement there is a default that throws an exception just in case another programmer would add a new enum value without updating the switch statement.  You may actually want to unit test and verify that an invalid enum would throw an exception.  Here's one way to achieve this, use an explicit cast:

enum DayOfWeek
{
    Monday,
    Tuesday
}

DayOfWeek badDayOfWeek = (DayOfWeek)(-1);

Trivial!  Yet its not something you may think of, because we've generally been trained to think that enums are ALWAYS supposed to be valid.

Better yet, get rid of your enums and your switch statements.

Wednesday, March 07, 2007 7:03:29 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Monday, March 05, 2007
My daughter's Dell Inspiron 1150 fell victim once again to bargain basement laptop design and ended up
flat lined on my desk this weekend with its guts completely removed.

The Patient



The culprit was a week power receptacle that popped off the mother board and needed to be resoldered for a second time. 

The culprit



Unfortunately when my daughter has the laptop on her lap, the power cable sometimes gets upward pressure applied from her legs bumping the power cord.  With only weak solder holding the receptacle on the main board its no wonder this thing has popped off twice now.  My IBM Thinkpad would never have this problem, the receptacle on it is firmly attached to not only the mother board, like this Dell, but also the case - freaking brilliant!

Laptop Completely Disassembled



This time was going to be different.  This time I dremiled the case to make a bit more room for a new metal reinforcement piece on the top of the receptacle to provide support for the receptacle from upward forces popping it off the mother board.

Reinstalled Receptacle With New Reinforcement



If you look really closely you can see a tiny piece of shiny metal sticking out above the power receptacle, this is the new reinforcement piece I soldered to the top of the receptacle.
Monday, March 05, 2007 7:56:59 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Thursday, February 22, 2007
I have a version of NAntRunner working in Visual Studio 2005.  I was questioning whether there was a real need for NAntRunner in Visual Studio 2005 considering we now have MSBuild, but NAnt is just plain better and I've just gotten too used to running Ant builds from Eclipse.

Unfortunately the conversion from Visual Studio 2003 to 2005 is not exactly just a registry edit since you must recompile the plugin in Visual Studio 2005 to reference EnvDTE80 and remove the Office.dll dependency (see this MSDN article: http://msdn2.microsoft.com/en-us/library/ms165634(VS.80).aspx).  The one nice thing about VS 2005 is that the add-in facilities are easier to work with so I was able to eliminate several of the C++ based hosting projects/dlls.  It seems to work just fine, but I still need to get the configuration loading/saving working.  I also need to fix the installer project to reflect the xcopy based VS 2005 add-in deployment model.

Ant
Thursday, February 22, 2007 8:51:03 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [1]  | 
# Tuesday, February 13, 2007
I've been catching up on my DVR'd 24 episodes, and I came across a part where pair programming would have helped them out tremendously at CTU.  Kind of funny that was the first thing that popped in my head.

Tuesday, February 13, 2007 5:02:41 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [2]  | 
# Monday, February 12, 2007
About a year ago, when .NET 2.0 first came out, I was toying with the idea of using the WWF for an internal ASP.NET application at work.  I finally decided against it last spring once it was decided .NET 3.0 would be required for WWF; .NET 3.0 wouldn't RTM for several months after the end of the project.  I haven't thought about WWF since then, that is until this weekend.  I've spent most of my free time this weekend immersed in WWF, and I must say that so far I'm really liking the technology much better.  I can finally see it being really useful in cases, especially in cases of long running workflow.

Originally I couldn't find much information on the WWF, I only had the Presenting Windows Workflow Foundation book, which I found not all that useful.  It was more of an overview rather than how to really implement anything - but it was better than nothing.  However I have found some articles recently posted by Scott Allen that are absolutely fantastic.

Monday, February 12, 2007 6:25:10 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Saturday, February 10, 2007
It's been several years since I've used Doxygen, but Ayende reminded me of its existance today.  I spent 2 minutes downloading it, setting it up, and then finally running it.  I forgot how fast Doxygen is, and the quality of the output is now very good on C#.  I will definately start using Doxygen again, its just so darned fast and simple.



Saturday, February 10, 2007 5:50:14 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |