Browse Source

Simplify LocalImageFile comparisons with record

pull/240/head
Ionite 1 year ago
parent
commit
9a07a7dff1
No known key found for this signature in database
  1. 32
      StabilityMatrix.Core/Models/Database/LocalImageFile.cs

32
StabilityMatrix.Core/Models/Database/LocalImageFile.cs

@ -1,5 +1,4 @@
using LiteDB; using StabilityMatrix.Core.Helper;
using StabilityMatrix.Core.Helper;
using StabilityMatrix.Core.Models.FileInterfaces; using StabilityMatrix.Core.Models.FileInterfaces;
using JsonSerializer = System.Text.Json.JsonSerializer; using JsonSerializer = System.Text.Json.JsonSerializer;
using Size = System.Drawing.Size; using Size = System.Drawing.Size;
@ -9,7 +8,7 @@ namespace StabilityMatrix.Core.Models.Database;
/// <summary> /// <summary>
/// Represents a locally indexed image file. /// Represents a locally indexed image file.
/// </summary> /// </summary>
public class LocalImageFile public record LocalImageFile
{ {
public required string AbsolutePath { get; init; } public required string AbsolutePath { get; init; }
@ -120,34 +119,15 @@ public class LocalImageFile
private sealed class LocalImageFileEqualityComparer : IEqualityComparer<LocalImageFile> private sealed class LocalImageFileEqualityComparer : IEqualityComparer<LocalImageFile>
{ {
public bool Equals(LocalImageFile? x, LocalImageFile? y) /// <inheritdoc />
public bool Equals(LocalImageFile x, LocalImageFile y)
{ {
if (ReferenceEquals(x, y)) return x == y;
return true;
if (ReferenceEquals(x, null))
return false;
if (ReferenceEquals(y, null))
return false;
if (x.GetType() != y.GetType())
return false;
return x.AbsolutePath == y.AbsolutePath
&& x.ImageType == y.ImageType
&& x.CreatedAt.Equals(y.CreatedAt)
&& x.LastModifiedAt.Equals(y.LastModifiedAt)
&& Equals(x.GenerationParameters, y.GenerationParameters)
&& Nullable.Equals(x.ImageSize, y.ImageSize);
} }
public int GetHashCode(LocalImageFile obj) public int GetHashCode(LocalImageFile obj)
{ {
return HashCode.Combine( return obj.GetHashCode();
obj.AbsolutePath,
obj.ImageType,
obj.CreatedAt,
obj.LastModifiedAt,
obj.GenerationParameters,
obj.ImageSize
);
} }
} }

Loading…
Cancel
Save