/// <summary> /// Get the next range (i.e. a contiguous range of integers) in ascending order. /// </summary> /// <param name="currentposition">The current position into this collection. Use 0 for the first time. On return, this is the next position.</param> /// <param name="result">Returns the next contiguous range if the return value is <c>true</c>.</param> /// <returns>True if the returned data are valid, false if there is no more data.</returns> /// <remarks>You can use this function in a while loop: /// <code> /// int rangestart, rangecount; /// int currentPosition=0; /// while(GetNextRangeAscending(ref currentPosition, out rangestart, out rangecount)) /// { /// // do your things here /// } /// </code></remarks> public bool GetNextRangeAscending(ref int currentposition, out ContiguousIntegerRange result) { int rangestart; int rangecount; if (currentposition < 0 || currentposition >= Count) { result = ContiguousIntegerRange.Empty; return(false); } else { rangestart = this[currentposition]; int previous = rangestart; rangecount = 1; for (currentposition = currentposition + 1; currentposition < Count; currentposition++) { if (this[currentposition] == (previous + 1)) { previous++; rangecount++; } else { break; } } result = ContiguousIntegerRange.FromStartAndCount(rangestart, rangecount); return(true); } }
/// <summary> /// Get the next range (i.e. a contiguous range of integers) in descending order. /// </summary> /// <param name="currentposition">The current position into this collection. Use Count-1 for the first time. On return, this is the next position.</param> /// <param name="result">Returns the next contiguous interger range if the return value is <c>true</c>.</param> /// <returns>True if the range data are valid, false if there is no more data. Used as end-of-loop indicator.</returns> /// <remarks>You can use this function in a while loop: /// <code> /// int rangestart, rangecount; /// int currentPosition=selection.Count-1; /// while(selection.GetNextRangeAscending(currentPosition,out rangestart, out rangecount)) /// { /// // do your things here /// } /// </code></remarks> public bool GetNextRangeDescending(ref int currentposition, out ContiguousIntegerRange result) { int rangestart, rangecount; if (currentposition < 0 || currentposition >= Count) { result = ContiguousIntegerRange.Empty; return(false); } else { rangestart = this[currentposition]; rangecount = 1; for (currentposition = currentposition - 1; currentposition >= 0; currentposition--) { if (this[currentposition] == (rangestart - 1)) { rangestart--; rangecount++; } else { break; } } result = ContiguousIntegerRange.FromStartAndCount(rangestart, rangecount); return(true); } }
public object Deserialize(object o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent) { var start = info.GetInt32("Start"); var count = info.GetInt32("Count"); return(ContiguousIntegerRange.FromStartAndCount(start, count)); }