Skip to content

Commit ad9c61d

Browse files
Fix multi-targeting build errors and add framework polyfills
Resolves build errors across all target frameworks (net5.0-net9.0, netstandard2.0-2.1) by adding missing polyfills and conditional compilation. Key changes: - Add ThrowHelper class with polyfills for ThrowIfGreaterThanOrEqual and other argument validation methods not available in older frameworks - Fix RuntimeHelpers.IsReferenceOrContainsReferences usage by falling back to typeof(T).IsValueType check for netstandard2.0/2.1 - Handle HashSet capacity constructor unavailability in netstandard2.0 - Implement manual hash code calculation for netstandard2.0 (HashCode.Combine not available) - Fix nullability warnings in TryGetValue methods by conditionally applying MaybeNullWhen attribute and using default! instead of default - Conditionally implement IReadOnlySet<T> interface only for NET5_0_OR_GREATER - Replace all ArgumentNullException/ArgumentOutOfRangeException.ThrowIf* calls with ThrowHelper equivalents for consistency Also includes code formatting improvements and test project configuration updates. Build now succeeds with 0 errors and 0 warnings across all target frameworks.
1 parent 34772db commit ad9c61d

41 files changed

Lines changed: 1142 additions & 545 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<AssemblyName>Containers.Benchmarks</AssemblyName>
8+
<RootNamespace>ktsu.Containers.Benchmarks</RootNamespace>
9+
</PropertyGroup>
210

3-
<PropertyGroup>
4-
<OutputType>Exe</OutputType>
5-
<TargetFramework>net9.0</TargetFramework>
6-
<ImplicitUsings>enable</ImplicitUsings>
7-
<Nullable>enable</Nullable>
8-
<AssemblyName>Containers.Benchmarks</AssemblyName>
9-
<RootNamespace>ktsu.Containers.Benchmarks</RootNamespace>
10-
</PropertyGroup>
11-
12-
<ItemGroup>
13-
<PackageReference Include="BenchmarkDotNet" />
14-
</ItemGroup>
15-
16-
<ItemGroup>
17-
<ProjectReference Include="..\Containers\Containers.csproj" />
18-
</ItemGroup>
11+
<ItemGroup>
12+
<PackageReference Include="BenchmarkDotNet" />
13+
</ItemGroup>
1914

15+
<ItemGroup>
16+
<ProjectReference Include="..\Containers\Containers.csproj" />
17+
</ItemGroup>
2018
</Project>

Containers.Benchmarks/ContiguousCollectionBenchmarks.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT license.
44

55
namespace ktsu.Containers.Benchmarks;
6+
67
using BenchmarkDotNet.Attributes;
78
using ktsu.Containers;
89

Containers.Benchmarks/ContiguousMapBenchmarks.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT license.
44

55
namespace ktsu.Containers.Benchmarks;
6+
67
using BenchmarkDotNet.Attributes;
78
using ktsu.Containers;
89

Containers.Benchmarks/ContiguousSetBenchmarks.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT license.
44

55
namespace ktsu.Containers.Benchmarks;
6+
67
using BenchmarkDotNet.Attributes;
78
using ktsu.Containers;
89

Containers.Benchmarks/CrossCollectionComparisonBenchmarks.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT license.
44

55
namespace ktsu.Containers.Benchmarks;
6+
67
using BenchmarkDotNet.Attributes;
78
using ktsu.Containers;
89

Containers.Benchmarks/GlobalSuppressions.cs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,38 @@
44

55
using System.Diagnostics.CodeAnalysis;
66

7-
[assembly: SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "Benchmark console output doesn't need localization")]
8-
[assembly: SuppressMessage("Design", "CA1002:Do not expose generic lists", Justification = "Benchmarks need to return specific collection types for measurement")]
9-
[assembly: SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Benchmark method names use underscores for clarity")]
10-
[assembly: SuppressMessage("Performance", "CA1812:Avoid uninstantiated internal classes", Justification = "Benchmark classes are instantiated by BenchmarkDotNet via reflection")]
11-
[assembly: SuppressMessage("Performance", "CA1852:Seal internal types", Justification = "Benchmark classes should not be sealed as they may be inherited by BenchmarkDotNet")]
12-
[assembly: SuppressMessage("Design", "CA1515:Consider making public types internal", Justification = "Benchmark classes must be public for BenchmarkDotNet discovery")]
13-
[assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Benchmark methods cannot be static - they need instance context for BenchmarkDotNet")]
7+
[assembly: SuppressMessage(
8+
"Globalization",
9+
"CA1303:Do not pass literals as localized parameters",
10+
Justification = "Benchmark console output doesn't need localization"
11+
)]
12+
[assembly: SuppressMessage(
13+
"Design",
14+
"CA1002:Do not expose generic lists",
15+
Justification = "Benchmarks need to return specific collection types for measurement"
16+
)]
17+
[assembly: SuppressMessage(
18+
"Naming",
19+
"CA1707:Identifiers should not contain underscores",
20+
Justification = "Benchmark method names use underscores for clarity"
21+
)]
22+
[assembly: SuppressMessage(
23+
"Performance",
24+
"CA1812:Avoid uninstantiated internal classes",
25+
Justification = "Benchmark classes are instantiated by BenchmarkDotNet via reflection"
26+
)]
27+
[assembly: SuppressMessage(
28+
"Performance",
29+
"CA1852:Seal internal types",
30+
Justification = "Benchmark classes should not be sealed as they may be inherited by BenchmarkDotNet"
31+
)]
32+
[assembly: SuppressMessage(
33+
"Design",
34+
"CA1515:Consider making public types internal",
35+
Justification = "Benchmark classes must be public for BenchmarkDotNet discovery"
36+
)]
37+
[assembly: SuppressMessage(
38+
"Performance",
39+
"CA1822:Mark members as static",
40+
Justification = "Benchmark methods cannot be static - they need instance context for BenchmarkDotNet"
41+
)]

Containers.Benchmarks/InsertionOrderMapBenchmarks.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT license.
44

55
namespace ktsu.Containers.Benchmarks;
6+
67
using BenchmarkDotNet.Attributes;
78
using ktsu.Containers;
89

Containers.Benchmarks/InsertionOrderSetBenchmarks.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT license.
44

55
namespace ktsu.Containers.Benchmarks;
6+
67
using BenchmarkDotNet.Attributes;
78
using ktsu.Containers;
89

Containers.Benchmarks/OrderedCollectionBenchmarks.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT license.
44

55
namespace ktsu.Containers.Benchmarks;
6+
67
using BenchmarkDotNet.Attributes;
78
using ktsu.Containers;
89

Containers.Benchmarks/OrderedSetBenchmarks.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT license.
44

55
namespace ktsu.Containers.Benchmarks;
6+
67
using BenchmarkDotNet.Attributes;
78
using ktsu.Containers;
89

0 commit comments

Comments
 (0)