Skip to content

Range unions implement IComparable<T> but not IComparable, so non-generic sorts throw #225

Closed

Description

@CaffeinatedCoder

Problem

The range unions implement IComparable<TRange> (#39) but not the non-generic IComparable. So List<IRange<int>>.Sort(), ArrayList.Sort() and any non-generic consumer (data grids, Comparer.Default) throw "At least one object must implement IComparable", although the docs say List.Sort() works with no comparer. A list of the concrete type, including List<Int32Range.Finite> through contravariance, works. Found by the pre-tag analysis (#179). It fails loudly.

Decision (maintainer, 2026-10-18)

Add the non-generic IComparable in 10.0.0 as part of #39's surface. It delegates to the same RangeOrder. A null argument sorts first, the same as the generic form. An argument that isn't the same range type throws ArgumentException.

Done when

Every range union (and RangeSet, if it has IComparable<RangeSet<…>>) implements IComparable. A discovered test holds that it agrees with IComparable<T> for every ordered shape pair and that a foreign argument throws. The docs' sorting sentence is true for List<IRange<T>>.

Activity

  1. added this to the 10.0.0 milestone on Oct 18, 2026
  2. added
    enhancement
    area/ranges
    package/nodatime
    package/core
    on Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/rangesenhancementpackage/corepackage/nodatime

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions