Skip to content

Commit

Permalink
Merge pull request #36 from diegofrata/fields
Browse files Browse the repository at this point in the history
Added support for fields.
  • Loading branch information
diegofrata authored Dec 9, 2022
2 parents 4c9a83e + 2eeb4d4 commit 431e8f6
Show file tree
Hide file tree
Showing 90 changed files with 671 additions and 245 deletions.
24 changes: 24 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/dotnet
{
"name": "C# (.NET)",
"image": "mcr.microsoft.com/devcontainers/dotnet:0-6.0",
"features": {
"ghcr.io/devcontainers/features/dotnet:1": {}
}

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [5000, 5001],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "dotnet restore",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
14 changes: 7 additions & 7 deletions Generator.Equals.Runtime/Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,43 @@ public class EquatableAttribute : Attribute
}

[Conditional("GENERATOR_EQUALS")]
[AttributeUsage(AttributeTargets.Property)]
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public class DefaultEqualityAttribute : Attribute
{
}

[Conditional("GENERATOR_EQUALS")]
[AttributeUsage(AttributeTargets.Property)]
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public class OrderedEqualityAttribute : Attribute
{
}

[Conditional("GENERATOR_EQUALS")]
[AttributeUsage(AttributeTargets.Property)]
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public class IgnoreEqualityAttribute : Attribute
{
}

[Conditional("GENERATOR_EQUALS")]
[AttributeUsage(AttributeTargets.Property)]
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public class UnorderedEqualityAttribute : Attribute
{
}

[Conditional("GENERATOR_EQUALS")]
[AttributeUsage(AttributeTargets.Property)]
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public class ReferenceEqualityAttribute : Attribute
{
}

[Conditional("GENERATOR_EQUALS")]
[AttributeUsage(AttributeTargets.Property)]
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public class SetEqualityAttribute : Attribute
{
}

[Conditional("GENERATOR_EQUALS")]
[AttributeUsage(AttributeTargets.Property)]
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public class CustomEqualityAttribute: Attribute
{
public Type EqualityType { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public bool Equals(global::Generator.Equals.Tests.Classes.CustomEquality.Sample?
{
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!)
&& 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!)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public bool Equals(global::Generator.Equals.Tests.Classes.DictionaryEquality.Sam
{
return
!ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::Generator.Equals.DictionaryEqualityComparer<string, int>.Default.Equals(Properties!, other.Properties!)
&& global::Generator.Equals.DictionaryEqualityComparer<string, int>.Default.Equals(this.Properties!, other.Properties!)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public bool Equals(global::Generator.Equals.Tests.Classes.ExplicitMode.Sample? o
{
return
!ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default.Equals(Age!, other.Age!)
&& global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default.Equals(this.Age!, other.Age!)
;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
65 changes: 65 additions & 0 deletions Generator.Equals.SnapshotTests/Classes/FieldEquality.verified.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//HintName: Generator.Equals.Tests.Classes.FieldEquality.Sample.Generator.Equals.g.cs

#nullable enable
#pragma warning disable CS0612,CS0618

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

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

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

return hashCode.ToHashCode();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public bool Equals(global::Generator.Equals.Tests.Classes.GenericParameterEquali
{
return
!ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::System.Collections.Generic.EqualityComparer<TName>.Default.Equals(Name!, other.Name!)
&& global::System.Collections.Generic.EqualityComparer<TAge>.Default.Equals(Age!, other.Age!)
&& global::System.Collections.Generic.EqualityComparer<TName>.Default.Equals(this.Name!, other.Name!)
&& global::System.Collections.Generic.EqualityComparer<TAge>.Default.Equals(this.Age!, other.Age!)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public bool Equals(global::Generator.Equals.Tests.Classes.IgnoreEquality.Sample?
{
return
!ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::System.Collections.Generic.EqualityComparer<global::System.String>.Default.Equals(Name!, other.Name!)
&& global::System.Collections.Generic.EqualityComparer<global::System.String>.Default.Equals(this.Name!, other.Name!)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public bool Equals(global::Generator.Equals.Tests.Classes.IgnoreInheritedMembers
{
return
!ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default.Equals(Age!, other.Age!)
&& global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default.Equals(this.Age!, other.Age!)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public bool Equals(global::Generator.Equals.Tests.Classes.MultiplePartialsEquali
{
return
!ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::Generator.Equals.OrderedEqualityComparer<string>.Default.Equals(Addresses!, other.Addresses!)
&& global::System.Collections.Generic.EqualityComparer<global::System.String>.Default.Equals(FirstName!, other.FirstName!)
&& global::System.Collections.Generic.EqualityComparer<global::System.String>.Default.Equals(LastName!, other.LastName!)
&& global::Generator.Equals.OrderedEqualityComparer<string>.Default.Equals(this.Addresses!, other.Addresses!)
&& global::System.Collections.Generic.EqualityComparer<global::System.String>.Default.Equals(this.FirstName!, other.FirstName!)
&& global::System.Collections.Generic.EqualityComparer<global::System.String>.Default.Equals(this.LastName!, other.LastName!)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public bool Equals(global::Generator.Equals.Tests.Classes.NonSupportedMembers.Sa
{
return
!ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::System.Collections.Generic.EqualityComparer<global::System.String>.Default.Equals(Name!, other.Name!)
&& global::System.Collections.Generic.EqualityComparer<global::System.String>.Default.Equals(this.Name!, other.Name!)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public bool Equals(global::Generator.Equals.Tests.Classes.NullableEquality.Sampl
{
return
!ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::Generator.Equals.OrderedEqualityComparer<string>.Default.Equals(Addresses!, other.Addresses!)
&& global::Generator.Equals.OrderedEqualityComparer<string>.Default.Equals(this.Addresses!, other.Addresses!)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public bool Equals(global::Generator.Equals.Tests.Classes.ObsoleteClass.Sample?
{
return
!ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::System.Collections.Generic.EqualityComparer<global::System.String>.Default.Equals(Something!, other.Something!)
&& global::System.Collections.Generic.EqualityComparer<global::System.String>.Default.Equals(this.Something!, other.Something!)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public bool Equals(global::Generator.Equals.Tests.Classes.ObsoleteMembers.Sample
{
return
!ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::System.Collections.Generic.EqualityComparer<global::System.String>.Default.Equals(NoComment!, other.NoComment!)
&& global::System.Collections.Generic.EqualityComparer<global::System.String>.Default.Equals(Comment!, other.Comment!)
&& global::System.Collections.Generic.EqualityComparer<global::System.String>.Default.Equals(this.NoComment!, other.NoComment!)
&& global::System.Collections.Generic.EqualityComparer<global::System.String>.Default.Equals(this.Comment!, other.Comment!)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public bool Equals(global::Generator.Equals.Tests.Classes.OrderedEquality.Sample
{
return
!ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::Generator.Equals.OrderedEqualityComparer<string>.Default.Equals(Addresses!, other.Addresses!)
&& global::Generator.Equals.OrderedEqualityComparer<string>.Default.Equals(this.Addresses!, other.Addresses!)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public bool Equals(global::Generator.Equals.Tests.Classes.PrimitiveEquality.Samp
{
return
!ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::System.Collections.Generic.EqualityComparer<global::System.String>.Default.Equals(Name!, other.Name!)
&& global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default.Equals(Age!, other.Age!)
&& global::System.Collections.Generic.EqualityComparer<global::System.String>.Default.Equals(this.Name!, other.Name!)
&& global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default.Equals(this.Age!, other.Age!)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public bool Equals(global::Generator.Equals.Tests.Classes.ReferenceEquality.Samp
{
return
!ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::Generator.Equals.ReferenceEqualityComparer<global::System.String>.Default.Equals(Name!, other.Name!)
&& global::Generator.Equals.ReferenceEqualityComparer<global::System.String>.Default.Equals(this.Name!, other.Name!)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public bool Equals(global::Generator.Equals.Tests.Classes.SetEquality.Sample? ot
{
return
!ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::Generator.Equals.SetEqualityComparer<int>.Default.Equals(Properties!, other.Properties!)
&& global::Generator.Equals.SetEqualityComparer<int>.Default.Equals(this.Properties!, other.Properties!)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public bool Equals(global::Generator.Equals.Tests.Classes.UnorderedEquality.Samp
{
return
!ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::Generator.Equals.UnorderedEqualityComparer<int>.Default.Equals(Properties!, other.Properties!)
&& global::Generator.Equals.UnorderedEqualityComparer<int>.Default.Equals(this.Properties!, other.Properties!)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ partial record struct Sample
public bool Equals(global::Generator.Equals.Tests.RecordStructs.CustomEquality.Sample other)
{
return true
&& global::Generator.Equals.Tests.RecordStructs.CustomEquality.Comparer1.Default.Equals(Name1!, other.Name1!)
&& global::Generator.Equals.Tests.RecordStructs.CustomEquality.Comparer2.Instance.Equals(Name2!, other.Name2!)
&& new global::Generator.Equals.Tests.RecordStructs.CustomEquality.LengthEqualityComparer().Equals(Name3!, other.Name3!)
&& global::Generator.Equals.Tests.RecordStructs.CustomEquality.Comparer1.Default.Equals(this.Name1!, other.Name1!)
&& global::Generator.Equals.Tests.RecordStructs.CustomEquality.Comparer2.Instance.Equals(this.Name2!, other.Name2!)
&& new global::Generator.Equals.Tests.RecordStructs.CustomEquality.LengthEqualityComparer().Equals(this.Name3!, other.Name3!)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ partial record struct Sample
public bool Equals(global::Generator.Equals.Tests.RecordStructs.DictionaryEquality.Sample other)
{
return true
&& global::Generator.Equals.DictionaryEqualityComparer<string, int>.Default.Equals(Properties!, other.Properties!)
&& global::Generator.Equals.DictionaryEqualityComparer<string, int>.Default.Equals(this.Properties!, other.Properties!)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ partial record struct Sample
public bool Equals(global::Generator.Equals.Tests.RecordStructs.ExplicitMode.Sample other)
{
return true
&& global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default.Equals(Age!, other.Age!)
&& global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default.Equals(this.Age!, other.Age!)
;
}

Expand Down
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,35 @@
//HintName: Generator.Equals.Tests.RecordsStructs.FieldEquality.Sample.Generator.Equals.g.cs

#nullable enable
#pragma warning disable CS0612,CS0618

namespace Generator.Equals.Tests.RecordsStructs
{
partial class FieldEquality
{
partial record struct Sample
{
/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public bool Equals(global::Generator.Equals.Tests.RecordsStructs.FieldEquality.Sample other)
{
return true
&& global::Generator.Equals.OrderedEqualityComparer<string>.Default.Equals(this._addresses!, other._addresses!)
;
}

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

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

0 comments on commit 431e8f6

Please sign in to comment.