U2U.ValueObjectComparers 0.2.0

Implement a ValueObject Equals and GetHashCode  method efficiently.

Install-Package U2U.ValueObjectComparers -Version 0.2.0
dotnet add package U2U.ValueObjectComparers --version 0.2.0
<PackageReference Include="U2U.ValueObjectComparers" Version="0.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add U2U.ValueObjectComparers --version 0.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Implement your Value Object Equals and GetHashCode efficiently.

public class SomeObject : IEquatable<SomeObject>
{
  public static bool operator ==(SomeObject left, SomeObject right)
    => ValueObjectComparer<SomeObject>.Instance.Equals(left, right);

  public static bool operator !=(SomeObject left, SomeObject right)
    => !(left == right);

  public string Name { get; set; }

  public int Age { get; set; }

  [Ignore]
  public int NotUsed { get; set; }

  public override bool Equals([AllowNull] object obj)
    => ValueObjectComparer<SomeObject>.Instance.Equals(this, obj);

  public bool Equals([AllowNull] SomeObject other)
    => ValueObjectComparer<SomeObject>.Instance.Equals(this, other);

  public override int GetHashCode()
    => ValueObjectComparer<SomeObject>.Instance.GetHashCode();
}

link

Implement your Value Object Equals and GetHashCode efficiently.

public class SomeObject : IEquatable<SomeObject>
{
  public static bool operator ==(SomeObject left, SomeObject right)
    => ValueObjectComparer<SomeObject>.Instance.Equals(left, right);

  public static bool operator !=(SomeObject left, SomeObject right)
    => !(left == right);

  public string Name { get; set; }

  public int Age { get; set; }

  [Ignore]
  public int NotUsed { get; set; }

  public override bool Equals([AllowNull] object obj)
    => ValueObjectComparer<SomeObject>.Instance.Equals(this, obj);

  public bool Equals([AllowNull] SomeObject other)
    => ValueObjectComparer<SomeObject>.Instance.Equals(this, other);

  public override int GetHashCode()
    => ValueObjectComparer<SomeObject>.Instance.GetHashCode();
}

link

Release Notes

Use at your own risk ;)

  • .NETStandard 2.0

    • No dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
0.2.0 210 12/31/2019
0.1.1 108 12/30/2019
0.1.0 78 12/26/2019