U2U.ValueObjectComparers 0.2.0

Implement a ValueObject Equals and GetHashCode  method efficiently.

There is a newer version of this package available.
See the version list below for details.
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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.2.0 101 4/7/2020
0.2.0 268 12/31/2019
0.1.1 158 12/30/2019
0.1.0 111 12/26/2019