public static void TestSortWithComparer() { // Provide a comparer { NonGenericElement12 item1 = new NonGenericElement12 { IntValue = 2 }; NonGenericElement12 item2 = new NonGenericElement12 { IntValue = 3 }; NonGenericElement12 item3 = new NonGenericElement12 { IntValue = 1 }; Driver <NonGenericElement12> .TestSortWithComparer( Producer.MakeEnumerable(item1, item2, item3), new NonGenericBaseComparer(), Producer.MakeEnumerable(item3, item1, item2)); } // Rely on IComparable<T> { ComparableElement1 item1 = new ComparableElement1 { IntValue = 2 }; ComparableElement1 item2 = new ComparableElement1 { IntValue = 3 }; ComparableElement1 item3 = new ComparableElement1 { IntValue = 1 }; Driver <ComparableElement1> .TestSortWithComparer( Producer.MakeEnumerable(item1, item2, item3), null, Producer.MakeEnumerable(item3, item1, item2)); } // Provide a comparer { StructWrapper <NonGenericElement12> item1 = new StructWrapper <NonGenericElement12> { Reference = new NonGenericElement12 { IntValue = 2 } }; StructWrapper <NonGenericElement12> item2 = new StructWrapper <NonGenericElement12> { Reference = new NonGenericElement12 { IntValue = 3 } }; StructWrapper <NonGenericElement12> item3 = new StructWrapper <NonGenericElement12> { Reference = new NonGenericElement12 { IntValue = 1 } }; Driver <StructWrapper <NonGenericElement12> > .TestSortWithComparer( Producer.MakeEnumerable(item1, item2, item3), new NonGenericWrappedBaseComparer <NonGenericElement12>(), Producer.MakeEnumerable(item3, item1, item2)); } // Rely on IComparable<T> { ComparableStructWrapper <ComparableElement1> item1 = new ComparableStructWrapper <ComparableElement1> { Reference = new ComparableElement1 { IntValue = 2 } }; ComparableStructWrapper <ComparableElement1> item2 = new ComparableStructWrapper <ComparableElement1> { Reference = new ComparableElement1 { IntValue = 3 } }; ComparableStructWrapper <ComparableElement1> item3 = new ComparableStructWrapper <ComparableElement1> { Reference = new ComparableElement1 { IntValue = 1 } }; Driver <ComparableStructWrapper <ComparableElement1> > .TestSortWithComparer( Producer.MakeEnumerable(item1, item2, item3), null, Producer.MakeEnumerable(item3, item1, item2)); } }
public int CompareTo(ComparableStructWrapper <T> other) { return(Reference.CompareTo(other.Reference)); }