diff --git a/Directory.Build.props b/Directory.Build.props index 8c3b316..c71829f 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,32 +1,32 @@ - - Library - enable - Latest - true + + Library + enable + Latest + true - ALTA Software llc. - Domain Primitives - ALTA Software llc. - Copyright © 2024 ALTA Software llc. - 2.0.0 - + ALTA Software llc. + Domain Primitives + ALTA Software llc. + Copyright © 2024 ALTA Software llc. + 2.0.1 + - - README.md - https://github.com/altasoft/DomainPrimitives - https://github.com/altasoft/DomainPrimitives - git - MIT - True - https://github.com/altasoft/DomainPrimitives - True - true - True - ddd;domain;entity;dotnet-core;value-object;strongly-typed; - + + README.md + https://github.com/altasoft/DomainPrimitives + https://github.com/altasoft/DomainPrimitives + git + MIT + True + https://github.com/altasoft/DomainPrimitives + True + true + True + ddd;domain;entity;dotnet-core;value-object;strongly-typed; + - - - + + + diff --git a/src/AltaSoft.DomainPrimitives.Generator/Helpers/MethodGeneratorHelper.cs b/src/AltaSoft.DomainPrimitives.Generator/Helpers/MethodGeneratorHelper.cs index 93fcd73..f4e7ae6 100644 --- a/src/AltaSoft.DomainPrimitives.Generator/Helpers/MethodGeneratorHelper.cs +++ b/src/AltaSoft.DomainPrimitives.Generator/Helpers/MethodGeneratorHelper.cs @@ -701,11 +701,27 @@ public static void GenerateEquatableOperators(string className, string fieldName builder.AppendInheritDoc() .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") - .AppendLine($"public static bool operator ==({className} left, {className} right) => left.Equals(right);"); + .Append($"public static bool operator ==({className}{nullable} left, {className}{nullable} right)"); + + if (isValueType) + { + builder.AppendLine(" => left.Equals(right);"); + } + else + { + builder.NewLine(); + builder.OpenBracket() + .AppendLine("if (ReferenceEquals(left, right))") + .AppendIndentation().AppendLine("return true;") + .AppendLine("if (left is null || right is null)") + .AppendIndentation().AppendLine("return false;") + .AppendLine("return left.Equals(right);") + .CloseBracket(); + } builder.AppendInheritDoc() - .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") - .AppendLine($"public static bool operator !=({className} left, {className} right) => !(left == right);"); + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine($"public static bool operator !=({className}{nullable} left, {className}{nullable} right) => !(left == right);"); } ///