Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement parameterless IComparable for StreamPosition and StreamRevision #111

Merged
merged 1 commit into from
May 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/EventStore.Client/StreamPosition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace EventStore.Client {
/// <summary>
/// A structure referring to an <see cref="EventRecord"/>'s position within a stream.
/// </summary>
public readonly struct StreamPosition : IEquatable<StreamPosition>, IComparable<StreamPosition> {
public readonly struct StreamPosition : IEquatable<StreamPosition>, IComparable<StreamPosition>, IComparable {
private readonly ulong _value;

/// <summary>
Expand Down Expand Up @@ -58,6 +58,13 @@ public StreamPosition(ulong value) {
/// <inheritdoc />
public int CompareTo(StreamPosition other) => _value.CompareTo(other._value);

/// <inheritdoc />
public int CompareTo(object? obj) => obj switch {
null => 1,
StreamPosition other => CompareTo(other),
_ => throw new ArgumentException("Object is not a StreamPosition"),
};

/// <inheritdoc />
public bool Equals(StreamPosition other) => _value == other._value;

Expand Down
9 changes: 8 additions & 1 deletion src/EventStore.Client/StreamRevision.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace EventStore.Client {
/// <summary>
/// A structure referring to the expected stream revision when writing to a stream.
/// </summary>
public readonly struct StreamRevision : IEquatable<StreamRevision>, IComparable<StreamRevision> {
public readonly struct StreamRevision : IEquatable<StreamRevision>, IComparable<StreamRevision>, IComparable {
private readonly ulong _value;

/// <summary>
Expand Down Expand Up @@ -53,6 +53,13 @@ public StreamRevision(ulong value) {
/// <inheritdoc />
public int CompareTo(StreamRevision other) => _value.CompareTo(other._value);

/// <inheritdoc />
public int CompareTo(object? obj) => obj switch {
null => 1,
StreamRevision other => CompareTo(other),
_ => throw new ArgumentException("Object is not a StreamRevision"),
};

/// <inheritdoc />
public bool Equals(StreamRevision other) => _value == other._value;

Expand Down