Tonight while building out some admin screens, I ran into a minor issue with Ambrose's SortableCollectionBase object[^]. In a situation where your collection has no records, an exception is thrown. Although this makes sense, it was not my intended behavior. So, I put in a fix. In the Sort(string sortExpression) method, I added a little bit of error trapping to look for this situation. Here's the code. If you want a friendlier error message than what you currently get with this object, just uncomment the throw line:
143public void Sort(string sortExpression) 144{ 145 #region Parameter Checks 146 if (sortExpression == null) 147 throw new ArgumentNullException("sortExpression", "Argument cannot be null."); 148 #endregion 149 150 if(this.InnerList.Count > 0) 151 { 152 this.InnerList.Sort(this.GetMultiComparer(this.List[0].GetType(), sortExpression)); 153 } 154 else 155 { 156 //throw new ApplicationException(string.Format("The collection you are attempting to sort has '{0}' records in it. Because of this, the sorting operation failed.",this.InnerList.Count)); 157 } 158} 159
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5