Skip to content

Commit

Permalink
Merge pull request #42 from diegofrata/deep-equality
Browse files Browse the repository at this point in the history
Fix the IEquatable<T> implementation so it works when comparing using base types
  • Loading branch information
diegofrata authored Jan 2, 2023
2 parents df90198 + 74583e8 commit 8df2a87
Show file tree
Hide file tree
Showing 43 changed files with 698 additions and 164 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//HintName: Generator.Equals.Tests.Classes.BaseEquality.Manager.Generator.Equals.g.cs

#nullable enable
#pragma warning disable CS0612,CS0618

namespace Generator.Equals.Tests.Classes
{
partial class BaseEquality
{
partial class Manager : global::System.IEquatable<Manager>
{
/// <summary>
/// Indicates whether the object on the left is equal to the object on the right.
/// </summary>
/// <param name="left">The left object</param>
/// <param name="right">The right object</param>
/// <returns>true if the objects are equal; otherwise, false.</returns>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public static bool operator ==(
global::Generator.Equals.Tests.Classes.BaseEquality.Manager? left,
global::Generator.Equals.Tests.Classes.BaseEquality.Manager? right) =>
global::Generator.Equals.DefaultEqualityComparer<global::Generator.Equals.Tests.Classes.BaseEquality.Manager?>.Default
.Equals(left, right);

/// <summary>
/// Indicates whether the object on the left is not equal to the object on the right.
/// </summary>
/// <param name="left">The left object</param>
/// <param name="right">The right object</param>
/// <returns>true if the objects are not equal; otherwise, false.</returns>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public static bool operator !=(global::Generator.Equals.Tests.Classes.BaseEquality.Manager? left, global::Generator.Equals.Tests.Classes.BaseEquality.Manager? right) =>
!(left == right);

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public override bool Equals(object? obj)
{
var other = obj as global::Generator.Equals.Tests.Classes.BaseEquality.Manager;
return
!ReferenceEquals(other, null) && base.Equals(obj)
&& global::Generator.Equals.DefaultEqualityComparer<global::System.String>.Default.Equals(this.Department!, other.Department!)
;
}
/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public bool Equals(global::Generator.Equals.Tests.Classes.BaseEquality.Manager? other) =>
Equals((object?) other);


/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public override int GetHashCode()
{
var hashCode = new global::System.HashCode();

hashCode.Add(base.GetHashCode());
hashCode.Add(
this.Department!,
global::Generator.Equals.DefaultEqualityComparer<global::System.String>.Default);

return hashCode.ToHashCode();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//HintName: Generator.Equals.Tests.Classes.BaseEquality.Person.Generator.Equals.g.cs

#nullable enable
#pragma warning disable CS0612,CS0618

namespace Generator.Equals.Tests.Classes
{
partial class BaseEquality
{
partial class Person : global::System.IEquatable<Person>
{
/// <summary>
/// Indicates whether the object on the left is equal to the object on the right.
/// </summary>
/// <param name="left">The left object</param>
/// <param name="right">The right object</param>
/// <returns>true if the objects are equal; otherwise, false.</returns>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public static bool operator ==(
global::Generator.Equals.Tests.Classes.BaseEquality.Person? left,
global::Generator.Equals.Tests.Classes.BaseEquality.Person? right) =>
global::Generator.Equals.DefaultEqualityComparer<global::Generator.Equals.Tests.Classes.BaseEquality.Person?>.Default
.Equals(left, right);

/// <summary>
/// Indicates whether the object on the left is not equal to the object on the right.
/// </summary>
/// <param name="left">The left object</param>
/// <param name="right">The right object</param>
/// <returns>true if the objects are not equal; otherwise, false.</returns>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public static bool operator !=(global::Generator.Equals.Tests.Classes.BaseEquality.Person? left, global::Generator.Equals.Tests.Classes.BaseEquality.Person? right) =>
!(left == right);

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public override bool Equals(object? obj)
{
var other = obj as global::Generator.Equals.Tests.Classes.BaseEquality.Person;
return
!ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::Generator.Equals.DefaultEqualityComparer<global::System.Int32>.Default.Equals(this.Age!, other.Age!)
;
}
/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public bool Equals(global::Generator.Equals.Tests.Classes.BaseEquality.Person? other) =>
Equals((object?) other);


/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public override int GetHashCode()
{
var hashCode = new global::System.HashCode();

hashCode.Add(this.GetType());
hashCode.Add(
this.Age!,
global::Generator.Equals.DefaultEqualityComparer<global::System.Int32>.Default);

return hashCode.ToHashCode();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//HintName: Generator.Equals.Tests.Classes.BaseEquality.Manager.Generator.Equals.g.cs

#nullable enable
#pragma warning disable CS0612,CS0618

namespace Generator.Equals.Tests.Classes
{
partial class BaseEquality
{
partial class Manager : global::System.IEquatable<Manager>
{
/// <summary>
/// Indicates whether the object on the left is equal to the object on the right.
/// </summary>
/// <param name="left">The left object</param>
/// <param name="right">The right object</param>
/// <returns>true if the objects are equal; otherwise, false.</returns>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public static bool operator ==(
global::Generator.Equals.Tests.Classes.BaseEquality.Manager? left,
global::Generator.Equals.Tests.Classes.BaseEquality.Manager? right) =>
global::Generator.Equals.DefaultEqualityComparer<global::Generator.Equals.Tests.Classes.BaseEquality.Manager?>.Default
.Equals(left, right);

/// <summary>
/// Indicates whether the object on the left is not equal to the object on the right.
/// </summary>
/// <param name="left">The left object</param>
/// <param name="right">The right object</param>
/// <returns>true if the objects are not equal; otherwise, false.</returns>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public static bool operator !=(global::Generator.Equals.Tests.Classes.BaseEquality.Manager? left, global::Generator.Equals.Tests.Classes.BaseEquality.Manager? right) =>
!(left == right);

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public override bool Equals(object? obj)
{
var other = obj as global::Generator.Equals.Tests.Classes.BaseEquality.Manager;
return
!ReferenceEquals(other, null) && base.Equals(obj)
&& global::Generator.Equals.DefaultEqualityComparer<global::System.String>.Default.Equals(this.Department!, other.Department!)
;
}
/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public bool Equals(global::Generator.Equals.Tests.Classes.BaseEquality.Manager? other) =>
Equals((object?) other);


/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public override int GetHashCode()
{
var hashCode = new global::System.HashCode();

hashCode.Add(base.GetHashCode());
hashCode.Add(
this.Department!,
global::Generator.Equals.DefaultEqualityComparer<global::System.String>.Default);

return hashCode.ToHashCode();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//HintName: Generator.Equals.Tests.Classes.BaseEquality.Person.Generator.Equals.g.cs

#nullable enable
#pragma warning disable CS0612,CS0618

namespace Generator.Equals.Tests.Classes
{
partial class BaseEquality
{
partial class Person : global::System.IEquatable<Person>
{
/// <summary>
/// Indicates whether the object on the left is equal to the object on the right.
/// </summary>
/// <param name="left">The left object</param>
/// <param name="right">The right object</param>
/// <returns>true if the objects are equal; otherwise, false.</returns>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public static bool operator ==(
global::Generator.Equals.Tests.Classes.BaseEquality.Person? left,
global::Generator.Equals.Tests.Classes.BaseEquality.Person? right) =>
global::Generator.Equals.DefaultEqualityComparer<global::Generator.Equals.Tests.Classes.BaseEquality.Person?>.Default
.Equals(left, right);

/// <summary>
/// Indicates whether the object on the left is not equal to the object on the right.
/// </summary>
/// <param name="left">The left object</param>
/// <param name="right">The right object</param>
/// <returns>true if the objects are not equal; otherwise, false.</returns>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public static bool operator !=(global::Generator.Equals.Tests.Classes.BaseEquality.Person? left, global::Generator.Equals.Tests.Classes.BaseEquality.Person? right) =>
!(left == right);

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public override bool Equals(object? obj)
{
var other = obj as global::Generator.Equals.Tests.Classes.BaseEquality.Person;
return
!ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::Generator.Equals.DefaultEqualityComparer<global::System.Int32>.Default.Equals(this.Age!, other.Age!)
;
}
/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public bool Equals(global::Generator.Equals.Tests.Classes.BaseEquality.Person? other) =>
Equals((object?) other);


/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public override int GetHashCode()
{
var hashCode = new global::System.HashCode();

hashCode.Add(this.GetType());
hashCode.Add(
this.Age!,
global::Generator.Equals.DefaultEqualityComparer<global::System.Int32>.Default);

return hashCode.ToHashCode();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,21 @@ partial class Sample : global::System.IEquatable<Sample>

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public override bool Equals(object? obj) =>
Equals(obj as global::Generator.Equals.Tests.Classes.CustomEquality.Sample);

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public bool Equals(global::Generator.Equals.Tests.Classes.CustomEquality.Sample? other)
public override bool Equals(object? obj)
{
var other = obj as global::Generator.Equals.Tests.Classes.CustomEquality.Sample;
return
!ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::Generator.Equals.Tests.Classes.CustomEquality.Comparer1.Default.Equals(this.Name1!, other.Name1!)
&& global::Generator.Equals.Tests.Classes.CustomEquality.Comparer2.Instance.Equals(this.Name2!, other.Name2!)
&& new global::Generator.Equals.Tests.Classes.CustomEquality.LengthEqualityComparer().Equals(this.Name3!, other.Name3!)
;
}
/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public bool Equals(global::Generator.Equals.Tests.Classes.CustomEquality.Sample? other) =>
Equals((object?) other);


/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,19 @@ partial class Manager : global::System.IEquatable<Manager>

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public override bool Equals(object? obj) =>
Equals(obj as global::Generator.Equals.Tests.Classes.DeepEquality.Manager);

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public bool Equals(global::Generator.Equals.Tests.Classes.DeepEquality.Manager? other)
public override bool Equals(object? obj)
{
var other = obj as global::Generator.Equals.Tests.Classes.DeepEquality.Manager;
return
base.Equals(other as global::Generator.Equals.Tests.Classes.DeepEquality.Person)
!ReferenceEquals(other, null) && base.Equals(obj)
&& global::Generator.Equals.DefaultEqualityComparer<global::System.String>.Default.Equals(this.Department!, other.Department!)
;
}
/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public bool Equals(global::Generator.Equals.Tests.Classes.DeepEquality.Manager? other) =>
Equals((object?) other);


/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,19 @@ partial class Person : global::System.IEquatable<Person>

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public override bool Equals(object? obj) =>
Equals(obj as global::Generator.Equals.Tests.Classes.DeepEquality.Person);

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public bool Equals(global::Generator.Equals.Tests.Classes.DeepEquality.Person? other)
public override bool Equals(object? obj)
{
var other = obj as global::Generator.Equals.Tests.Classes.DeepEquality.Person;
return
!ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::Generator.Equals.DefaultEqualityComparer<global::System.Int32>.Default.Equals(this.Age!, other.Age!)
;
}
/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public bool Equals(global::Generator.Equals.Tests.Classes.DeepEquality.Person? other) =>
Equals((object?) other);


/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,19 @@ partial class Sample : global::System.IEquatable<Sample>

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public override bool Equals(object? obj) =>
Equals(obj as global::Generator.Equals.Tests.Classes.DeepEquality.Sample);

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public bool Equals(global::Generator.Equals.Tests.Classes.DeepEquality.Sample? other)
public override bool Equals(object? obj)
{
var other = obj as global::Generator.Equals.Tests.Classes.DeepEquality.Sample;
return
!ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::Generator.Equals.DefaultEqualityComparer<global::Generator.Equals.Tests.Classes.DeepEquality.Person>.Default.Equals(this.Person!, other.Person!)
;
}
/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public bool Equals(global::Generator.Equals.Tests.Classes.DeepEquality.Sample? other) =>
Equals((object?) other);


/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
Expand Down
Loading

0 comments on commit 8df2a87

Please sign in to comment.