public static string NotEmptyNameValueCollectionAsString(NameValueCollection coll, string sComment /* = "" */) { if (CollectionsHelper.IsNullOrEmpty(coll)) { return(""); } return(NameValueCollectionAsString(coll, sComment)); }
/// <summary> /// /// </summary> /// <param name="listOfDates">Expect ascending sequence of dates</param> /// <returns>List of ranges for contiguous sequense</returns> /// <remarks>E.g for sequence 1,2,3, 6,7,8,9, 11,12, 14, 18 it should return ranges /// (1,3) ,(6,9), (11,12), (14,14), (18,18) /// </remarks> public static List <DateTimeRange> BuildContiguousGroupsList(List <DateTime> listOfDates) { Debug.Assert(!CollectionsHelper.IsNullOrEmpty(listOfDates), "Investigate why?. ."); DateTime startOfRange = DateTime.MinValue; DateTime prevItem = DateTime.MinValue; List <DateTimeRange> listOfRanges = new List <DateTimeRange>(); for (int i = 0; i < listOfDates.Count; i++) { DateTime item = listOfDates[i]; if (startOfRange == DateTime.MinValue) { startOfRange = item; } else//not the first { Debug.Assert(item >= prevItem, "Expect ascending sequence"); if (prevItem.AddDays(1) == item) {//contiguous, continue } else {//save the range listOfRanges.Add(new DateTimeRange(startOfRange, prevItem)); startOfRange = item; } } if (i == listOfDates.Count - 1) {//The last, close current range listOfRanges.Add(new DateTimeRange(startOfRange, item)); break; } prevItem = item; } Debug.Assert(listOfRanges.Count > 0); return(listOfRanges); }