Skip to content

Commit

Permalink
increment IEquatable<IQuote>, still fails
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveSkender committed Feb 4, 2024
1 parent 35bd585 commit 185f788
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
19 changes: 5 additions & 14 deletions src/_common/Quotes/Quote.Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@ public bool Equals(IQuote? other)
=> base.Equals(other);
}

public abstract class EquatableQuote<TQuote>()
where TQuote : IQuote
public abstract class EquatableQuote : IQuote
{
// IMPORTANT: this does not override the general Equals(objA, objB),
// so don't use it for equality comparison.

public virtual DateTime TickDate { get; set; }
public virtual decimal Open { get; set; }
public virtual decimal High { get; set; }
Expand All @@ -42,14 +38,10 @@ public abstract class EquatableQuote<TQuote>()
public virtual decimal Volume { get; set; }

public override bool Equals(object? obj)
=> this.Equals(obj);
=> this.Equals(obj as IQuote);

public bool Equals(IQuote? other)
=> Equals(other);

public bool Equals(TQuote? other)
{

if (other is null)
{
return false;
Expand All @@ -68,8 +60,6 @@ public bool Equals(TQuote? other)
}

// Return true if the fields match.
// Note that the base class is not invoked because it is
// System.Object, which defines Equals as reference equality.
return (TickDate == other.TickDate)
&& (Open == other.Open)
&& (High == other.High)
Expand All @@ -79,7 +69,7 @@ public bool Equals(TQuote? other)
}

public static bool operator
==(EquatableQuote<TQuote> lhs, EquatableQuote<TQuote> rhs)
==(EquatableQuote lhs, EquatableQuote rhs)
{
if (lhs is null)
{
Expand All @@ -92,12 +82,13 @@ public static bool operator
// Only the left side is null.
return false;
}

// Equals handles the case of null on right side.
return lhs.Equals(rhs);
}

public static bool operator
!=(EquatableQuote<TQuote> lhs, EquatableQuote<TQuote> rhs)
!=(EquatableQuote lhs, EquatableQuote rhs)
=> !(lhs == rhs);

public override int GetHashCode()
Expand Down
4 changes: 2 additions & 2 deletions tests/other/PublicApi.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ internal sealed class MyEma : IResult
public double? Ema { get; set; }
}

internal sealed class MyCustomQuote
: EquatableQuote<MyCustomQuote>, IQuote
internal class MyCustomQuote

Check failure on line 20 in tests/other/PublicApi.Tests.cs

View workflow job for this annotation

GitHub Actions / unit tests

Type 'MyCustomQuote' can be sealed because it has no subtypes in its containing assembly and is not externally visible (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1852)

Check failure on line 20 in tests/other/PublicApi.Tests.cs

View workflow job for this annotation

GitHub Actions / unit tests

Type 'MyCustomQuote' can be sealed because it has no subtypes in its containing assembly and is not externally visible (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1852)
: EquatableQuote, IQuote
{
// redirect inherited base properties
DateTime ISeries.TickDate => CloseDate;
Expand Down

0 comments on commit 185f788

Please sign in to comment.