In MiscUtil (
http://pobox.com/~skeet/csharp/miscutil) we have a
ProjectionComparer and an extension method, so you can say:
IComparer<Customercomparer =
* * ProjectionComparer.Create(cust =cust.LastName)
* * * *.ThenBy(ProjectionComparer.Create(cust =cust.FirstName));
etc
This could probably be beefed up even further with a bit of effort, to
be honest.
--
Jon Skeet - <sk...@pobox.com>
Web site:http://www.pobox.com/~skeet*
Blog:http://www.msmvps.com/jon_skeet
C# in Depth:http://csharpindepth.com- Hide quoted text -
- Show quoted text -
Stuck back in my 2.0 world, I have written this before:
private delegate int lameComparison();
private static int customerComparer(Customer lhs, Customer rhs)
{
lameComparison[] comparisons = {
delegate() { return
Comparer<string>.Default.Compare(lhs.LastName, rhs.LastName); },
delegate() { return
Comparer<string>.Default.Compare(lhs.FirstName, rhs.FirstName); },
};
int result = 0;
for (int i = 0; i != comparisons.Length && result == 0; ++i)
{
result = comparisons[i]();
}
return result;
}
However, this not only makes my coworkers froth at the mouth, it has
performance hits (minimal).
One more reason to move to 3.0.
Thanks,
Travis