private void InsertIntervalRelativeTo(Interval toInsert, Interval relativeTo, string where) { if (relativeTo == null) { intervals.Add(toInsert); } else { var index = Intervals.IndexOf(relativeTo); if ("after".Equals(where)) { if (index != -1) { intervals.Insert(++index, toInsert); } else { intervals.Add(toInsert); } } if ("before".Equals(where)) { Intervals.Insert(index, toInsert); } } FirePropertyChanged("HasIntervals"); RefreshTemplate(); }
public void TestInsertIntervals() { var v1 = new Interval(1, 2); var v2 = new Interval(3, 5); var v3 = new Interval(6, 7); var v4 = new Interval(8, 10); var v5 = new Interval(12, 16); var vs = new[] { v1, v2, v3, v4, v5 }; var r = Intervals.Insert(vs, new Interval(4, 8)); Assert.AreEqual(r.Count, 3); Assert.AreEqual(r[0].Start, 1); Assert.AreEqual(r[1].End, 10); Assert.AreEqual(r[2].End, 16); }