Skip to content

Commit

Permalink
Fixed null value handling in == and != operator generation for class …
Browse files Browse the repository at this point in the history
…types
  • Loading branch information
GregoryNikolaishvili committed Feb 7, 2024
1 parent 945183c commit a2b9df5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 30 deletions.
54 changes: 27 additions & 27 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
<Project>
<PropertyGroup>
<OutputType>Library</OutputType>
<Nullable>enable</Nullable>
<LangVersion>Latest</LangVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PropertyGroup>
<OutputType>Library</OutputType>
<Nullable>enable</Nullable>
<LangVersion>Latest</LangVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>

<Authors>ALTA Software llc.</Authors>
<Product>Domain Primitives</Product>
<Company>ALTA Software llc.</Company>
<Copyright>Copyright © 2024 ALTA Software llc.</Copyright>
<Version>2.0.0</Version>
</PropertyGroup>
<Authors>ALTA Software llc.</Authors>
<Product>Domain Primitives</Product>
<Company>ALTA Software llc.</Company>
<Copyright>Copyright © 2024 ALTA Software llc.</Copyright>
<Version>2.0.1</Version>
</PropertyGroup>

<PropertyGroup>
<PackageReadmeFile>README.md</PackageReadmeFile>
<ProjectUrl>https://github.com/altasoft/DomainPrimitives</ProjectUrl>
<RepositoryUrl>https://github.com/altasoft/DomainPrimitives</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageProjectUrl>https://github.com/altasoft/DomainPrimitives</PackageProjectUrl>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<EnableNETAnalyzers>True</EnableNETAnalyzers>
<PackageTags>ddd;domain;entity;dotnet-core;value-object;strongly-typed;</PackageTags>
</PropertyGroup>
<PropertyGroup>
<PackageReadmeFile>README.md</PackageReadmeFile>
<ProjectUrl>https://github.com/altasoft/DomainPrimitives</ProjectUrl>
<RepositoryUrl>https://github.com/altasoft/DomainPrimitives</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageProjectUrl>https://github.com/altasoft/DomainPrimitives</PackageProjectUrl>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<EnableNETAnalyzers>True</EnableNETAnalyzers>
<PackageTags>ddd;domain;entity;dotnet-core;value-object;strongly-typed;</PackageTags>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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);");
}

/// <summary>
Expand Down

0 comments on commit a2b9df5

Please sign in to comment.