Browse Source

Make ImageProperty a readonly struct

af/merge-core
Jason Nelson 8 years ago
parent
commit
dd9b1738eb
  1. 23
      src/ImageSharp/MetaData/ImageProperty.cs
  2. 18
      tests/ImageSharp.Tests/MetaData/ImagePropertyTests.cs

23
src/ImageSharp/MetaData/ImageProperty.cs

@ -10,10 +10,10 @@ namespace SixLabors.ImageSharp.MetaData
/// the copyright information, the date, where the image was created /// the copyright information, the date, where the image was created
/// or some other information. /// or some other information.
/// </summary> /// </summary>
public class ImageProperty : IEquatable<ImageProperty> public readonly struct ImageProperty : IEquatable<ImageProperty>
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ImageProperty"/> class. /// Initializes a new instance of the <see cref="ImageProperty"/> struct.
/// </summary> /// </summary>
/// <param name="name">The name of the property.</param> /// <param name="name">The name of the property.</param>
/// <param name="value">The value of the property.</param> /// <param name="value">The value of the property.</param>
@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.MetaData
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ImageProperty"/> class /// Initializes a new instance of the <see cref="ImageProperty"/> struct
/// by making a copy from another property. /// by making a copy from another property.
/// </summary> /// </summary>
/// <param name="other"> /// <param name="other">
@ -71,11 +71,6 @@ namespace SixLabors.ImageSharp.MetaData
/// </returns> /// </returns>
public static bool operator ==(ImageProperty left, ImageProperty right) public static bool operator ==(ImageProperty left, ImageProperty right)
{ {
if (ReferenceEquals(left, right))
{
return true;
}
return left.Equals(right); return left.Equals(right);
} }
@ -110,7 +105,7 @@ namespace SixLabors.ImageSharp.MetaData
/// </returns> /// </returns>
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
return obj is ImageProperty other && Equals(other); return obj is ImageProperty other && this.Equals(other);
} }
/// <summary> /// <summary>
@ -153,16 +148,6 @@ namespace SixLabors.ImageSharp.MetaData
/// <param name="other">An object to compare with this object.</param> /// <param name="other">An object to compare with this object.</param>
public bool Equals(ImageProperty other) 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); return this.Name.Equals(other.Name) && Equals(this.Value, other.Value);
} }
} }

18
tests/ImageSharp.Tests/MetaData/ImagePropertyTests.cs

@ -18,13 +18,11 @@ namespace SixLabors.ImageSharp.Tests
[Fact] [Fact]
public void AreEqual() public void AreEqual()
{ {
ImageProperty property1 = new ImageProperty("Foo", "Bar"); var property1 = new ImageProperty("Foo", "Bar");
ImageProperty property2 = new ImageProperty("Foo", "Bar"); var property2 = new ImageProperty("Foo", "Bar");
ImageProperty property3 = null;
Assert.Equal(property1, property2); Assert.Equal(property1, property2);
Assert.True(property1 == property2); Assert.True(property1 == property2);
Assert.Null(property3);
} }
/// <summary> /// <summary>
@ -33,15 +31,13 @@ namespace SixLabors.ImageSharp.Tests
[Fact] [Fact]
public void AreNotEqual() public void AreNotEqual()
{ {
ImageProperty property1 = new ImageProperty("Foo", "Bar"); var property1 = new ImageProperty("Foo", "Bar");
ImageProperty property2 = new ImageProperty("Foo", "Foo"); var property2 = new ImageProperty("Foo", "Foo");
ImageProperty property3 = new ImageProperty("Bar", "Bar"); var property3 = new ImageProperty("Bar", "Bar");
ImageProperty property4 = new ImageProperty("Foo", null); var property4 = new ImageProperty("Foo", null);
Assert.False(property1.Equals("Foo")); Assert.False(property1.Equals("Foo"));
Assert.NotNull(property1);
Assert.NotEqual(property1, property2); Assert.NotEqual(property1, property2);
Assert.True(property1 != property2); Assert.True(property1 != property2);
@ -66,7 +62,7 @@ namespace SixLabors.ImageSharp.Tests
[Fact] [Fact]
public void ConstructorAssignsProperties() public void ConstructorAssignsProperties()
{ {
ImageProperty property = new ImageProperty("Foo", null); var property = new ImageProperty("Foo", null);
Assert.Equal("Foo", property.Name); Assert.Equal("Foo", property.Name);
Assert.Null(property.Value); Assert.Null(property.Value);

Loading…
Cancel
Save