diff --git a/src/ImageSharp/FormattedImage.cs b/src/ImageSharp/FormattedImage.cs index 5617be351..9b604eced 100644 --- a/src/ImageSharp/FormattedImage.cs +++ b/src/ImageSharp/FormattedImage.cs @@ -8,14 +8,14 @@ using SixLabors.ImageSharp.Formats; namespace SixLabors.ImageSharp { /// - /// Struct to curry and for return from async overloads. + /// Struct to curry and for return from async overloads. /// - public readonly struct FormattedImage + public readonly struct FormattedImage : IEquatable { /// /// Initializes a new instance of the struct. /// - /// The . + /// The . /// The . public FormattedImage(Image image, IImageFormat format) { @@ -34,41 +34,57 @@ namespace SixLabors.ImageSharp public readonly IImageFormat Format { get; } /// - /// Converts to + /// Converts to . /// /// The to convert. public static implicit operator (Image image, IImageFormat format)(FormattedImage value) - { - return (value.Image, value.Format); - } + => (value.Image, value.Format); /// /// Converts to /// /// The to convert. public static implicit operator FormattedImage((Image image, IImageFormat format) value) - { - return new FormattedImage(value.image, value.format); - } + => new FormattedImage(value.image, value.format); + + /// + /// Compares two objects for equality. + /// + /// The on the left side of the operand. + /// The on the right side of the operand. + /// + /// True if the parameter is equal to the parameter; otherwise, false. + /// + public static bool operator ==(FormattedImage left, FormattedImage right) + => left.Equals(right); + + /// + /// Compares two objects for inequality. + /// + /// The on the left side of the operand. + /// The on the right side of the operand. + /// + /// True if the parameter is not equal to the parameter; otherwise, false. + /// + public static bool operator !=(FormattedImage left, FormattedImage right) + => !(left == right); /// public override bool Equals(object obj) - { - return obj is FormattedImage other && - EqualityComparer.Default.Equals(this.Image, other.Image) && - EqualityComparer.Default.Equals(this.Format, other.Format); - } + => obj is FormattedImage image && this.Equals(image); /// - public override int GetHashCode() - { - return HashCode.Combine(this.Image, this.Format); - } + public bool Equals(FormattedImage other) + => EqualityComparer.Default.Equals(this.Image, other.Image) + && EqualityComparer.Default.Equals(this.Format, other.Format); + + /// + public override int GetHashCode() => HashCode.Combine(this.Image, this.Format); /// /// Deconstructs into component parts. /// - /// The . + /// The . /// The . public void Deconstruct(out Image image, out IImageFormat format) { diff --git a/src/ImageSharp/FormattedImageInfo.cs b/src/ImageSharp/FormattedImageInfo.cs index b3f854fc4..72368be34 100644 --- a/src/ImageSharp/FormattedImageInfo.cs +++ b/src/ImageSharp/FormattedImageInfo.cs @@ -10,7 +10,7 @@ namespace SixLabors.ImageSharp /// /// Struct to curry and for return from async overloads. /// - public readonly struct FormattedImageInfo + public readonly struct FormattedImageInfo : IEquatable { /// /// Initializes a new instance of the struct. @@ -38,32 +38,46 @@ namespace SixLabors.ImageSharp /// /// The to convert. public static implicit operator (IImageInfo imageInfo, IImageFormat format)(FormattedImageInfo value) - { - return (value.ImageInfo, value.Format); - } + => (value.ImageInfo, value.Format); /// /// Converts to /// /// The to convert. public static implicit operator FormattedImageInfo((IImageInfo imageInfo, IImageFormat format) value) - { - return new FormattedImageInfo(value.imageInfo, value.format); - } + => new FormattedImageInfo(value.imageInfo, value.format); + + /// + /// Compares two objects for equality. + /// + /// The on the left side of the operand. + /// The on the right side of the operand. + /// + /// True if the parameter is equal to the parameter; otherwise, false. + /// + public static bool operator ==(FormattedImageInfo left, FormattedImageInfo right) => left.Equals(right); + + /// + /// Compares two objects for inequality. + /// + /// The on the left side of the operand. + /// The on the right side of the operand. + /// + /// True if the parameter is not equal to the parameter; otherwise, false. + /// + public static bool operator !=(FormattedImageInfo left, FormattedImageInfo right) => !(left == right); /// public override bool Equals(object obj) - { - return obj is FormattedImageInfo other && - EqualityComparer.Default.Equals(this.ImageInfo, other.ImageInfo) && - EqualityComparer.Default.Equals(this.Format, other.Format); - } + => obj is FormattedImageInfo info && this.Equals(info); /// - public override int GetHashCode() - { - return HashCode.Combine(this.ImageInfo, this.Format); - } + public bool Equals(FormattedImageInfo other) + => EqualityComparer.Default.Equals(this.ImageInfo, other.ImageInfo) + && EqualityComparer.Default.Equals(this.Format, other.Format); + + /// + public override int GetHashCode() => HashCode.Combine(this.ImageInfo, this.Format); /// /// Deconstructs into component parts. diff --git a/src/ImageSharp/FormattedImage{TPixel}.cs b/src/ImageSharp/FormattedImage{TPixel}.cs index dc4609b7e..bb3eeabe7 100644 --- a/src/ImageSharp/FormattedImage{TPixel}.cs +++ b/src/ImageSharp/FormattedImage{TPixel}.cs @@ -9,16 +9,16 @@ using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp { /// - /// Struct to curry and for return from async overloads. + /// Struct to curry and for return from async overloads. /// /// The pixel format. - public readonly struct FormattedImage + public readonly struct FormattedImage : IEquatable> where TPixel : unmanaged, IPixel { /// /// Initializes a new instance of the struct. /// - /// The . + /// The . /// The . public FormattedImage(Image image, IImageFormat format) { @@ -41,37 +41,53 @@ namespace SixLabors.ImageSharp /// /// The to convert. public static implicit operator (Image image, IImageFormat format)(FormattedImage value) - { - return (value.Image, value.Format); - } + => (value.Image, value.Format); /// /// Converts to /// /// The to convert. public static implicit operator FormattedImage((Image image, IImageFormat format) value) - { - return new FormattedImage(value.image, value.format); - } + => new FormattedImage(value.image, value.format); + + /// + /// Compares two objects for equality. + /// + /// The on the left side of the operand. + /// The on the right side of the operand. + /// + /// True if the parameter is equal to the parameter; otherwise, false. + /// + public static bool operator ==(FormattedImage left, FormattedImage right) + => left.Equals(right); + + /// + /// Compares two objects for inequality. + /// + /// The on the left side of the operand. + /// The on the right side of the operand. + /// + /// True if the parameter is not equal to the parameter; otherwise, false. + /// + public static bool operator !=(FormattedImage left, FormattedImage right) + => !(left == right); /// public override bool Equals(object obj) - { - return obj is FormattedImage other && - EqualityComparer>.Default.Equals(this.Image, other.Image) && - EqualityComparer.Default.Equals(this.Format, other.Format); - } + => obj is FormattedImage image && this.Equals(image); /// - public override int GetHashCode() - { - return HashCode.Combine(this.Image, this.Format); - } + public bool Equals(FormattedImage other) + => EqualityComparer>.Default.Equals(this.Image, other.Image) + && EqualityComparer.Default.Equals(this.Format, other.Format); + + /// + public override int GetHashCode() => HashCode.Combine(this.Image, this.Format); /// /// Deconstructs into component parts. /// - /// The . + /// The . /// The . public void Deconstruct(out Image image, out IImageFormat format) {