Skip to content

Commit e13cb4d

Browse files
committed
Use HashCode from Microsoft.Bcl.HashCode
1 parent 53964fc commit e13cb4d

5 files changed

+8
-18
lines changed

Directory.Packages.props

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<PackageVersion Include="coverlet.msbuild" Version="6.0.2" />
1010
<PackageVersion Include="DocFx.App" Version="2.77.0" />
1111
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1" />
12+
<PackageVersion Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
1213
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
1314
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0" />
1415
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />

Source/SuperLinq.Async/SuperLinq.Async.csproj

+7-6
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,13 @@
124124
<ProjectReference Include="..\SuperLinq\SuperLinq.csproj" />
125125
</ItemGroup>
126126

127-
<ItemGroup Condition="$(TargetFramework) == 'netstandard2.0'">
128-
<PackageReference Include="System.Memory" PrivateAssets="All" />
129-
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
130-
<_Parameter1>SuperLinq.Async.Test</_Parameter1>
131-
</AssemblyAttribute>
132-
</ItemGroup>
127+
<ItemGroup Condition="$(TargetFramework) == 'netstandard2.0'">
128+
<PackageReference Include="Microsoft.Bcl.HashCode" />
129+
<PackageReference Include="System.Memory" />
130+
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
131+
<_Parameter1>SuperLinq.Async.Test</_Parameter1>
132+
</AssemblyAttribute>
133+
</ItemGroup>
133134

134135
<PropertyGroup Label="SourceGenerator">
135136
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>

Source/SuperLinq/KeyValuePairEqualityComparer.cs

-4
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,8 @@ public bool Equals(KeyValuePair<TKey, TValue> x, KeyValuePair<TKey, TValue> y) =
4848
&& _valueComparer.Equals(x.Value, y.Value);
4949

5050
public int GetHashCode(KeyValuePair<TKey, TValue> obj) =>
51-
#if NETCOREAPP
5251
HashCode.Combine(
5352
_keyComparer.GetHashCode(obj.Key!),
5453
_valueComparer.GetHashCode(obj.Value!));
55-
#else
56-
_keyComparer.GetHashCode(obj.Key) * 397 ^ _valueComparer.GetHashCode(obj.Value);
57-
#endif
5854
}
5955
}

Source/SuperLinq/ValueTupleEqualityComparer.cs

-4
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,8 @@ public bool Equals(
8787
&& _comparer2.Equals(x.Item2, y.Item2);
8888

8989
public int GetHashCode((T1, T2) obj) =>
90-
#if NETCOREAPP
9190
HashCode.Combine(
9291
_comparer1.GetHashCode(obj.Item1!),
9392
_comparer2.GetHashCode(obj.Item2!));
94-
#else
95-
_comparer1.GetHashCode(obj.Item1) * 397 ^ _comparer2.GetHashCode(obj.Item2);
96-
#endif
9793
}
9894
}

Tests/SuperLinq.Test/ValueTupleEqualityComparerTest.cs

-4
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,7 @@ public void ValueTupleEqualityComparerWithTwoTypeArgsShouldGetHashCode()
7979
var comparer = ValueTupleEqualityComparer.Create<int, int>(comparer1: null, comparer2: null);
8080
ValueTuple<int, int> first = new(1, 2);
8181
var firstHashCode = comparer.GetHashCode(first);
82-
#if NETCOREAPP
8382
var expectedHashCode = HashCode.Combine(1.GetHashCode(), 2.GetHashCode());
84-
#else
85-
var expectedHashCode = 1.GetHashCode() * 397 ^ 2.GetHashCode();
86-
#endif
8783
Assert.Equal(expectedHashCode, firstHashCode);
8884
}
8985
}

0 commit comments

Comments
 (0)