From dd9b1738eb422386b3a37b34937833e64f71bb3b Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Mon, 26 Mar 2018 19:03:49 -0700 Subject: [PATCH] Make ImageProperty a readonly struct --- src/ImageSharp/MetaData/ImageProperty.cs | 23 ++++--------------- .../MetaData/ImagePropertyTests.cs | 18 ++++++--------- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/src/ImageSharp/MetaData/ImageProperty.cs b/src/ImageSharp/MetaData/ImageProperty.cs index a663573763..e4f60e8b33 100644 --- a/src/ImageSharp/MetaData/ImageProperty.cs +++ b/src/ImageSharp/MetaData/ImageProperty.cs @@ -10,10 +10,10 @@ namespace SixLabors.ImageSharp.MetaData /// the copyright information, the date, where the image was created /// or some other information. /// - public class ImageProperty : IEquatable + public readonly struct ImageProperty : IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the struct. /// /// The name of the property. /// The value of the property. @@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.MetaData } /// - /// Initializes a new instance of the class + /// Initializes a new instance of the struct /// by making a copy from another property. /// /// @@ -71,11 +71,6 @@ namespace SixLabors.ImageSharp.MetaData /// public static bool operator ==(ImageProperty left, ImageProperty right) { - if (ReferenceEquals(left, right)) - { - return true; - } - return left.Equals(right); } @@ -110,7 +105,7 @@ namespace SixLabors.ImageSharp.MetaData /// public override bool Equals(object obj) { - return obj is ImageProperty other && Equals(other); + return obj is ImageProperty other && this.Equals(other); } /// @@ -153,16 +148,6 @@ namespace SixLabors.ImageSharp.MetaData /// An object to compare with this object. public bool Equals(ImageProperty other) { - if (ReferenceEquals(other, null)) - { - return false; - } - - if (ReferenceEquals(this, other)) - { - return true; - } - return this.Name.Equals(other.Name) && Equals(this.Value, other.Value); } } diff --git a/tests/ImageSharp.Tests/MetaData/ImagePropertyTests.cs b/tests/ImageSharp.Tests/MetaData/ImagePropertyTests.cs index 5e15d556c0..b5886522a8 100644 --- a/tests/ImageSharp.Tests/MetaData/ImagePropertyTests.cs +++ b/tests/ImageSharp.Tests/MetaData/ImagePropertyTests.cs @@ -18,13 +18,11 @@ namespace SixLabors.ImageSharp.Tests [Fact] public void AreEqual() { - ImageProperty property1 = new ImageProperty("Foo", "Bar"); - ImageProperty property2 = new ImageProperty("Foo", "Bar"); - ImageProperty property3 = null; + var property1 = new ImageProperty("Foo", "Bar"); + var property2 = new ImageProperty("Foo", "Bar"); Assert.Equal(property1, property2); Assert.True(property1 == property2); - Assert.Null(property3); } /// @@ -33,15 +31,13 @@ namespace SixLabors.ImageSharp.Tests [Fact] public void AreNotEqual() { - ImageProperty property1 = new ImageProperty("Foo", "Bar"); - ImageProperty property2 = new ImageProperty("Foo", "Foo"); - ImageProperty property3 = new ImageProperty("Bar", "Bar"); - ImageProperty property4 = new ImageProperty("Foo", null); + var property1 = new ImageProperty("Foo", "Bar"); + var property2 = new ImageProperty("Foo", "Foo"); + var property3 = new ImageProperty("Bar", "Bar"); + var property4 = new ImageProperty("Foo", null); Assert.False(property1.Equals("Foo")); - Assert.NotNull(property1); - Assert.NotEqual(property1, property2); Assert.True(property1 != property2); @@ -66,7 +62,7 @@ namespace SixLabors.ImageSharp.Tests [Fact] public void ConstructorAssignsProperties() { - ImageProperty property = new ImageProperty("Foo", null); + var property = new ImageProperty("Foo", null); Assert.Equal("Foo", property.Name); Assert.Null(property.Value);