public void CreateComparerFromDelegate() { var source = new List <int> { 1, 2, 3, 0, 4, 5, 6, 7 }; var comparer = ComparerHelper.CreateComparer <int>( (x, y) => { if (x == 0) { return(y == 0 ? 0 : -1); } if (y == 0) { return(1); } return(y.CompareTo(x)); }); var sorted = source.OrderBy(x => x, comparer).ToList(); var expected = new List <int> { 0, 7, 6, 5, 4, 3, 2, 1 }; CollectionAssert.AreEqual(expected, sorted); }
/// <summary> /// Find the index of a rectangle that contains the specified point. /// </summary> /// <param name="point">the target point</param> /// <returns>the rectangle index</returns> private int FindRectangleIndex(ScreenPoint point) { IComparer <OxyRect> comparer; if (this.IsTransposed()) { comparer = ComparerHelper.CreateComparer <OxyRect>( (x, y) => { if (x.Bottom < point.Y) { return(1); } if (x.Top > point.Y) { return(-1); } return(0); }); } else { comparer = ComparerHelper.CreateComparer <OxyRect>( (x, y) => { if (x.Right < point.X) { return(-1); } if (x.Left > point.X) { return(1); } return(0); }); } return(this.rectangles.BinarySearch(0, this.rectangles.Count, new OxyRect(), comparer)); }
/// <summary> /// Find the index of a rectangle that contains the specified point. /// </summary> /// <param name="point">the target point</param> /// <returns>the rectangle index</returns> private int FindRectangleIndex(ScreenPoint point) { var comparer = ComparerHelper.CreateComparer <OxyRect>( (x, y) => { if (x.Right < point.X) { return(-1); } if (x.Left > point.X) { return(1); } return(0); }); return(this.rectangles.BinarySearch(0, this.rectangles.Count, new OxyRect(), comparer)); }