Skip to content

Commit

Permalink
Merge pull request #31 from HavenDV/readable-generated-code
Browse files Browse the repository at this point in the history
feat: generated code is now more readable.
  • Loading branch information
diegofrata authored Sep 19, 2022
2 parents 1fcc5c5 + d279459 commit ba87406
Show file tree
Hide file tree
Showing 38 changed files with 1,767 additions and 1,186 deletions.
117 changes: 68 additions & 49 deletions Generator.Equals.SnapshotTests/Classes/CustomEquality.verified.cs
Original file line number Diff line number Diff line change
@@ -1,54 +1,73 @@
//HintName: Generator.Equals.Tests.Classes.CustomEquality.Sample.Generator.Equals.g.cs
namespace Generator.Equals.Tests.Classes {
partial class CustomEquality {
partial class Sample : global::System.IEquatable<Sample> {

#nullable enable
#pragma warning disable CS0612,CS0618
/// <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.CustomEquality.Sample? left, global::Generator.Equals.Tests.Classes.CustomEquality.Sample? right) => global::System.Collections.Generic.EqualityComparer<global::Generator.Equals.Tests.Classes.CustomEquality.Sample?>.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.CustomEquality.Sample? left, global::Generator.Equals.Tests.Classes.CustomEquality.Sample? right) => !(left == right);
/// <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) {
return !ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::Generator.Equals.Tests.Classes.CustomEquality.Comparer1.Default.Equals(Name1!, other.Name1!)
&& global::Generator.Equals.Tests.Classes.CustomEquality.Comparer2.Instance.Equals(Name2!, other.Name2!)
&& new global::Generator.Equals.Tests.Classes.CustomEquality.LengthEqualityComparer().Equals(Name3!, other.Name3!)
;
}
/// <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.Name1!, global::Generator.Equals.Tests.Classes.CustomEquality.Comparer1.Default
);
hashCode.Add(this.Name2!, global::Generator.Equals.Tests.Classes.CustomEquality.Comparer2.Instance
);
hashCode.Add(this.Name3!, new global::Generator.Equals.Tests.Classes.CustomEquality.LengthEqualityComparer()
);
return hashCode.ToHashCode();
}
#pragma warning restore CS0612,CS0618
#nullable restore
}

}
namespace Generator.Equals.Tests.Classes
{
partial class CustomEquality
{
partial class Sample : global::System.IEquatable<Sample>
{
/// <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.CustomEquality.Sample? left,
global::Generator.Equals.Tests.Classes.CustomEquality.Sample? right) =>
global::System.Collections.Generic.EqualityComparer<global::Generator.Equals.Tests.Classes.CustomEquality.Sample?>.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.CustomEquality.Sample? left, global::Generator.Equals.Tests.Classes.CustomEquality.Sample? right) =>
!(left == right);

/// <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)
{
return
!ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::Generator.Equals.Tests.Classes.CustomEquality.Comparer1.Default.Equals(Name1!, other.Name1!)
&& global::Generator.Equals.Tests.Classes.CustomEquality.Comparer2.Instance.Equals(Name2!, other.Name2!)
&& new global::Generator.Equals.Tests.Classes.CustomEquality.LengthEqualityComparer().Equals(Name3!, other.Name3!)
;
}

/// <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.Name1!,
global::Generator.Equals.Tests.Classes.CustomEquality.Comparer1.Default);
hashCode.Add(
this.Name2!,
global::Generator.Equals.Tests.Classes.CustomEquality.Comparer2.Instance);
hashCode.Add(
this.Name3!,
new global::Generator.Equals.Tests.Classes.CustomEquality.LengthEqualityComparer());

return hashCode.ToHashCode();
}
}
}
}
102 changes: 60 additions & 42 deletions Generator.Equals.SnapshotTests/Classes/DictionaryEquality.verified.cs
Original file line number Diff line number Diff line change
@@ -1,47 +1,65 @@
//HintName: Generator.Equals.Tests.Classes.DictionaryEquality.Sample.Generator.Equals.g.cs
namespace Generator.Equals.Tests.Classes {
partial class DictionaryEquality {
partial class Sample : global::System.IEquatable<Sample> {

#nullable enable
#pragma warning disable CS0612,CS0618
/// <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.DictionaryEquality.Sample? left, global::Generator.Equals.Tests.Classes.DictionaryEquality.Sample? right) => global::System.Collections.Generic.EqualityComparer<global::Generator.Equals.Tests.Classes.DictionaryEquality.Sample?>.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.DictionaryEquality.Sample? left, global::Generator.Equals.Tests.Classes.DictionaryEquality.Sample? right) => !(left == right);
/// <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.DictionaryEquality.Sample);
/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public bool Equals(global::Generator.Equals.Tests.Classes.DictionaryEquality.Sample? other) {
return !ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::Generator.Equals.DictionaryEqualityComparer<string, int>.Default.Equals(Properties!, other.Properties!)
;
}
/// <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.Properties!, global::Generator.Equals.DictionaryEqualityComparer<string, int>.Default);
return hashCode.ToHashCode();
}
#pragma warning restore CS0612,CS0618
#nullable restore
}

}
namespace Generator.Equals.Tests.Classes
{
partial class DictionaryEquality
{
partial class Sample : global::System.IEquatable<Sample>
{
/// <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.DictionaryEquality.Sample? left,
global::Generator.Equals.Tests.Classes.DictionaryEquality.Sample? right) =>
global::System.Collections.Generic.EqualityComparer<global::Generator.Equals.Tests.Classes.DictionaryEquality.Sample?>.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.DictionaryEquality.Sample? left, global::Generator.Equals.Tests.Classes.DictionaryEquality.Sample? right) =>
!(left == right);

/// <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.DictionaryEquality.Sample);

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public bool Equals(global::Generator.Equals.Tests.Classes.DictionaryEquality.Sample? other)
{
return
!ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::Generator.Equals.DictionaryEqualityComparer<string, int>.Default.Equals(Properties!, other.Properties!)
;
}

/// <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.Properties!,
global::Generator.Equals.DictionaryEqualityComparer<string, int>.Default);

return hashCode.ToHashCode();
}
}
}
}
102 changes: 60 additions & 42 deletions Generator.Equals.SnapshotTests/Classes/ExplicitMode.verified.cs
Original file line number Diff line number Diff line change
@@ -1,47 +1,65 @@
//HintName: Generator.Equals.Tests.Classes.ExplicitMode.Sample.Generator.Equals.g.cs
namespace Generator.Equals.Tests.Classes {
partial class ExplicitMode {
partial class Sample : global::System.IEquatable<Sample> {

#nullable enable
#pragma warning disable CS0612,CS0618
/// <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.ExplicitMode.Sample? left, global::Generator.Equals.Tests.Classes.ExplicitMode.Sample? right) => global::System.Collections.Generic.EqualityComparer<global::Generator.Equals.Tests.Classes.ExplicitMode.Sample?>.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.ExplicitMode.Sample? left, global::Generator.Equals.Tests.Classes.ExplicitMode.Sample? right) => !(left == right);
/// <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.ExplicitMode.Sample);
/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public bool Equals(global::Generator.Equals.Tests.Classes.ExplicitMode.Sample? other) {
return !ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default.Equals(Age!, other.Age!)
;
}
/// <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::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default);
return hashCode.ToHashCode();
}
#pragma warning restore CS0612,CS0618
#nullable restore
}

}
namespace Generator.Equals.Tests.Classes
{
partial class ExplicitMode
{
partial class Sample : global::System.IEquatable<Sample>
{
/// <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.ExplicitMode.Sample? left,
global::Generator.Equals.Tests.Classes.ExplicitMode.Sample? right) =>
global::System.Collections.Generic.EqualityComparer<global::Generator.Equals.Tests.Classes.ExplicitMode.Sample?>.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.ExplicitMode.Sample? left, global::Generator.Equals.Tests.Classes.ExplicitMode.Sample? right) =>
!(left == right);

/// <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.ExplicitMode.Sample);

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public bool Equals(global::Generator.Equals.Tests.Classes.ExplicitMode.Sample? other)
{
return
!ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default.Equals(Age!, other.Age!)
;
}

/// <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::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default);

return hashCode.ToHashCode();
}
}
}
}
Loading

0 comments on commit ba87406

Please sign in to comment.