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
/// or some other information.
/// </summary>
public class ImageProperty : IEquatable<ImageProperty>
public readonly struct ImageProperty : IEquatable<ImageProperty>
{
/// <summary>
/// Initializes a new instance of the <see cref="ImageProperty"/> class.
/// Initializes a new instance of the <see cref="ImageProperty"/> struct.
/// </summary>
/// <param name="name">The name of the property.</param>
/// <param name="value">The value of the property.</param>
@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.MetaData
}
/// <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.
/// </summary>
/// <param name="other">
@ -71,11 +71,6 @@ namespace SixLabors.ImageSharp.MetaData
/// </returns>
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
/// </returns>
public override bool Equals(object obj)
{
return obj is ImageProperty other && Equals(other);
return obj is ImageProperty other && this.Equals(other);
}
/// <summary>
@ -153,16 +148,6 @@ namespace SixLabors.ImageSharp.MetaData
/// <param name="other">An object to compare with this object.</param>
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);
}
}

18
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);
}
/// <summary>
@ -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);

Loading…
Cancel
Save