Skip to content

Commit

Permalink
Use Enum Comparison Version 4.79
Browse files Browse the repository at this point in the history
  • Loading branch information
GregFinzer committed Jan 28, 2023
1 parent e352762 commit d199f9f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
2 changes: 2 additions & 0 deletions Compare-NET-Objects-Tests/CompareDictionaryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void TestDictionary()

Dictionary<string, Person> dict2 = Common.CloneWithSerialization(dict1);

_compare.Config.DateTimeKindToUseWhenUnspecified = DateTimeKind.Local;
ComparisonResult result = _compare.Compare(dict1, dict2);

if (!result.AreEqual)
Expand All @@ -75,6 +76,7 @@ public void TestDictionaryNegative()

dict2["1002"].DateCreated = DateTime.Now.AddDays(1);

_compare.Config.DateTimeKindToUseWhenUnspecified = DateTimeKind.Local;
var result = _compare.Compare(dict1, dict2);

Assert.IsFalse(result.AreEqual);
Expand Down
2 changes: 2 additions & 0 deletions Compare-NET-Objects-Tests/CompareIListTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public void ArrayTest()
array2[0] = Common.CloneWithSerialization(p1);
array2[1] = Common.CloneWithSerialization(p2);

_compare.Config.DateTimeKindToUseWhenUnspecified = DateTimeKind.Local;
ComparisonResult result = _compare.Compare(array1, array2);

if (!result.AreEqual)
Expand Down Expand Up @@ -190,6 +191,7 @@ public void ArrayTestNegative()
array2[1] = Common.CloneWithSerialization(p2);
array2[1].Name = "Bob";

_compare.Config.DateTimeKindToUseWhenUnspecified = DateTimeKind.Local;
Assert.IsFalse(_compare.Compare(array1, array2).AreEqual);
}

Expand Down
10 changes: 6 additions & 4 deletions Compare-NET-Objects/Compare-NET-Objects.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@
<PackageTags>compare comparison equality equal deep objects difference compareobjects deepequal deepequals</PackageTags>
<Description>What you have been waiting for. Perform a deep compare of any two .NET objects using reflection. Shows the differences between the two objects.</Description>
<Authors>gfinzer</Authors>
<Version>4.78.0</Version>
<AssemblyVersion>4.78.0.0</AssemblyVersion>
<Version>4.79.0</Version>
<AssemblyVersion>4.79.0.0</AssemblyVersion>
<NeutralLanguage>en-US</NeutralLanguage>
<Company>Kellerman Software</Company>
<PackageReleaseNotes>Bump Newtonsoft.Json from 12.0.1 to 13.0.1
<PackageReleaseNotes>ShowCollectionKeyName Config option by gordon-matt https://github.com/GregFinzer/Compare-Net-Objects/pull/275
CompareBackingFields config option by Mch-Kuzyk https://github.com/GregFinzer/Compare-Net-Objects/pull/279

</PackageReleaseNotes>
<Copyright>Copyright © 2023</Copyright>
<FileVersion>4.78.0.0</FileVersion>
<FileVersion>4.79.0.0</FileVersion>

<PackageLicenseFile>License.txt</PackageLicenseFile>
<PackageIcon>NuGetIcon.png</PackageIcon>
<Title>Compare .NET Objects</Title>


</PropertyGroup>
Expand Down
39 changes: 23 additions & 16 deletions Compare-NET-Objects/RootComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,7 @@ public bool Compare(CompareParms parms)
}
else
{
BaseTypeComparer typeComparer = TypeComparers.FirstOrDefault(o => o.IsTypeMatch(t1, t2));

if (typeComparer != null)
{
if (parms.Config.IgnoreObjectTypes || !TypesDifferent(parms, t1, t2))
{
typeComparer.CompareType(parms);
}
}
else
{
if (EitherObjectIsNull(parms)) return false;

if (!parms.Config.IgnoreObjectTypes && t1 != null)
throw new NotSupportedException("Cannot compare object of type " + t1.Name);
}
if (!PerformBaseTypeComparison(parms, t1, t2)) return false;
}

}
Expand All @@ -80,6 +65,28 @@ public bool Compare(CompareParms parms)
return parms.Result.AreEqual;
}

private bool PerformBaseTypeComparison(CompareParms parms, Type t1, Type t2)
{
BaseTypeComparer typeComparer = TypeComparers.FirstOrDefault(o => o.IsTypeMatch(t1, t2));

if (typeComparer != null)
{
if (parms.Config.IgnoreObjectTypes || !TypesDifferent(parms, t1, t2))
{
typeComparer.CompareType(parms);
}
}
else
{
if (EitherObjectIsNull(parms)) return false;

if (!parms.Config.IgnoreObjectTypes && t1 != null)
throw new NotSupportedException("Cannot compare object of type " + t1.Name);
}

return true;
}

private bool TypesDifferent(CompareParms parms, Type t1, Type t2)
{
//Objects must be the same type and not be null
Expand Down
2 changes: 1 addition & 1 deletion Compare-NET-Objects/RootComparerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private static RootComparer BuildRootComparer()
_rootComparer.TypeComparers.Add(new TimespanComparer(_rootComparer));
_rootComparer.TypeComparers.Add(new StructComparer(_rootComparer));
_rootComparer.TypeComparers.Add(new ImmutableArrayComparer(_rootComparer));

_rootComparer.TypeComparers.Add(new EnumComparer(_rootComparer));
return _rootComparer;
}
#endregion
Expand Down

0 comments on commit d199f9f

Please sign in to comment.