Skip to content

Conversation

@Dreamescaper
Copy link

Today I have realized that the code like this fails:

messages.Max(message => message.Offset);

Despite having < or > operators, Offset does not implement IComparable, so this code fails with an exception:

  Message: 
System.ArgumentException : At least one object must implement IComparable.

  Stack Trace: 
Comparer.Compare(Object a, Object b)
ObjectComparer`1.Compare(T x, T y)
Enumerable.Max[TSource,TResult](IEnumerable`1 source, Func`2 selector)

I decided to submit a PR fixing that.

Checklist

  • Contains customer facing changes? (Interface implemented)
  • Including API/behavior changes
  • Did you add sufficient unit test and/or integration test coverage for this PR?

@Copilot Copilot AI review requested due to automatic review settings October 22, 2025 09:21
@Dreamescaper Dreamescaper requested review from a team as code owners October 22, 2025 09:21
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds IComparable<T> implementation to the Offset and Partition structs, enabling use of LINQ operations like Max() and Min() that require comparable types.

Key changes:

  • Implements IComparable<Partition> and IComparable<Offset> interfaces
  • Adds CompareTo methods that delegate to the underlying Value property's comparison
  • Includes comprehensive unit tests for the new comparison functionality

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/Confluent.Kafka/Partition.cs Adds IComparable<Partition> interface and CompareTo method implementation
src/Confluent.Kafka/Offset.cs Adds IComparable<Offset> interface and CompareTo method implementation
test/Confluent.Kafka.UnitTests/Partition.cs Adds unit tests verifying CompareTo behavior for equal, greater, and lesser values
test/Confluent.Kafka.UnitTests/Offset.cs Adds unit tests verifying CompareTo behavior for equal, greater, and lesser values

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@Dreamescaper Dreamescaper force-pushed the implement-icomparable branch from 7d047c4 to 7f36800 Compare October 22, 2025 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant