A Generic Sorter For Strongly-Typed Collections
Late last night I was doing some development work on a website for our investment club. I had a strongly-typed collection of “Stock” objects, and wanted to be able to sort them on any parameter (StockName, SharePrice, Volume, MarketCap, etc..) in either descending or ascending order. I didn’t want to have to write a separate comparer for each property. Reflection to the rescue! Below is a GenericSorter class, the use of which allows for the development of a Sort() method on the collection taking as a parameter the name of the property on which to sort. Smart. ...








