From fe60daf7e8232e460f2876130c5eed8727632a7a Mon Sep 17 00:00:00 2001 From: Jeremy Knight <492328+jeremyknight-me@users.noreply.github.com> Date: Wed, 13 Nov 2024 22:44:27 -0600 Subject: [PATCH] upgraded to dotnet9 (#116) * updated nuget packages * updated project versions * removed .net version compiler directive * ran dotnet format * Update ci-common-abstractions.yml * Update ci-common-data-sql.yml * Update ci-common-efcore-sql.yml * Update ci-common-efcore.yml * Update ci-common-fluentvalidation.yml * Update ci-common.yml --- .github/workflows/ci-common-abstractions.yml | 2 +- .github/workflows/ci-common-data-sql.yml | 3 +- .github/workflows/ci-common-efcore-sql.yml | 3 +- .github/workflows/ci-common-efcore.yml | 3 +- .../workflows/ci-common-fluentvalidation.yml | 3 +- .github/workflows/ci-common.yml | 2 +- src/Directory.Build.props | 2 +- src/JK.Common.Abstractions/CHANGELOG.md | 10 +++ .../JK.Common.Abstractions.csproj | 4 +- .../Parameters/ParameterAssertHelper.cs | 2 +- .../JK.Common.Data.Sql.Tests.csproj | 2 +- src/JK.Common.Data.Sql/CHANGELOG.md | 10 ++- .../Extensions/SqlBulkCopyExtensions.cs | 43 +++++----- src/JK.Common.Data.Sql/IsExternalInit.cs | 9 +- .../JK.Common.Data.Sql.csproj | 4 +- .../SqlBulkInsertOperation.cs | 2 +- .../CHANGELOG.md | 8 +- .../ModelConfigurationBuilderExtensions.cs | 6 +- ...ommon.EntityFrameworkCore.SqlServer.csproj | 12 +-- ...JK.Common.EntityFrameworkCore.Tests.csproj | 17 ++-- .../CHANGELOG.md | 5 +- .../JK.Common.EntityFrameworkCore.csproj | 15 ++-- .../JK.Common.FluentValidation.Tests.csproj | 2 +- src/JK.Common.FluentValidation/CHANGELOG.md | 10 ++- .../JK.Common.FluentValidation.csproj | 4 +- .../Extensions/StringExtensionsTest.cs | 1 - src/JK.Common.Tests/JK.Common.Tests.csproj | 2 +- .../Sorting/InsertionSortTests.cs | 65 +++++++-------- .../Sorting/SelectionSortTests.cs | 65 +++++++-------- .../TypeHelpers/DecimalHelperTests.cs | 39 +++++---- .../TypeHelpers/StringHelperTests/Slice.cs | 2 +- src/JK.Common/CHANGELOG.md | 7 +- .../DistanceUnitAbbreviationFactory.cs | 25 +++--- src/JK.Common/Extensions/TypeExtensions.cs | 1 + src/JK.Common/IsExternalInit.cs | 9 +- src/JK.Common/JK.Common.csproj | 4 +- .../Patterns/Singleton/LockedSingleton.cs | 1 + src/JK.Common/RangePolyfill.cs | 64 ++++++++------ src/JK.Common/Sorting/BubbleSort.cs | 19 ++--- src/JK.Common/Sorting/HeapSort.cs | 46 +++++----- src/JK.Common/Sorting/MergeSort.cs | 83 +++++++++---------- src/JK.Common/Sorting/QuickSort.cs | 2 + src/JK.Common/Sorting/ShellSort.cs | 1 + 43 files changed, 322 insertions(+), 297 deletions(-) diff --git a/.github/workflows/ci-common-abstractions.yml b/.github/workflows/ci-common-abstractions.yml index 98f223e..3741f82 100644 --- a/.github/workflows/ci-common-abstractions.yml +++ b/.github/workflows/ci-common-abstractions.yml @@ -26,7 +26,7 @@ jobs: uses: actions/setup-dotnet@v3 with: dotnet-version: | - 6.x + 9.x 8.x - name: Build run: dotnet build ./src/JK.Common.Abstractions/JK.Common.Abstractions.csproj -c Release diff --git a/.github/workflows/ci-common-data-sql.yml b/.github/workflows/ci-common-data-sql.yml index ad3643b..7092356 100644 --- a/.github/workflows/ci-common-data-sql.yml +++ b/.github/workflows/ci-common-data-sql.yml @@ -28,7 +28,8 @@ jobs: uses: actions/setup-dotnet@v3 with: dotnet-version: | - 6.x + 9.x + 8.x - name: Build run: dotnet build ./src/JK.Common.Data.Sql/JK.Common.Data.Sql.csproj -c Release - name: Test diff --git a/.github/workflows/ci-common-efcore-sql.yml b/.github/workflows/ci-common-efcore-sql.yml index a012dc2..c985a23 100644 --- a/.github/workflows/ci-common-efcore-sql.yml +++ b/.github/workflows/ci-common-efcore-sql.yml @@ -27,6 +27,7 @@ jobs: uses: actions/setup-dotnet@v3 with: dotnet-version: | - 6.x + 9.x + 8.x - name: Build run: dotnet build ./src/JK.Common.EntityFrameworkCore.SqlServer/JK.Common.EntityFrameworkCore.SqlServer.csproj -c Release diff --git a/.github/workflows/ci-common-efcore.yml b/.github/workflows/ci-common-efcore.yml index 4cd50d2..fefd835 100644 --- a/.github/workflows/ci-common-efcore.yml +++ b/.github/workflows/ci-common-efcore.yml @@ -28,7 +28,8 @@ jobs: uses: actions/setup-dotnet@v3 with: dotnet-version: | - 6.x + 9.x + 8.x - name: Build run: dotnet build ./src/JK.Common.EntityFrameworkCore/JK.Common.EntityFrameworkCore.csproj -c Release - name: Test diff --git a/.github/workflows/ci-common-fluentvalidation.yml b/.github/workflows/ci-common-fluentvalidation.yml index f9ecfd6..e72971d 100644 --- a/.github/workflows/ci-common-fluentvalidation.yml +++ b/.github/workflows/ci-common-fluentvalidation.yml @@ -28,7 +28,8 @@ jobs: uses: actions/setup-dotnet@v3 with: dotnet-version: | - 6.x + 9.x + 8.x - name: Build run: dotnet build ./src/JK.Common.FluentValidation/JK.Common.FluentValidation.csproj -c Release - name: Test diff --git a/.github/workflows/ci-common.yml b/.github/workflows/ci-common.yml index 7ced886..8c67220 100644 --- a/.github/workflows/ci-common.yml +++ b/.github/workflows/ci-common.yml @@ -28,7 +28,7 @@ jobs: uses: actions/setup-dotnet@v3 with: dotnet-version: | - 6.x + 9.x 8.x - name: Build run: dotnet build ./src/JK.Common/JK.Common.csproj -c Release diff --git a/src/Directory.Build.props b/src/Directory.Build.props index cef14e2..4ce81fc 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,6 +1,6 @@ - 12.0 + 13.0 disable disable diff --git a/src/JK.Common.Abstractions/CHANGELOG.md b/src/JK.Common.Abstractions/CHANGELOG.md index b74f7ab..4e6260a 100644 --- a/src/JK.Common.Abstractions/CHANGELOG.md +++ b/src/JK.Common.Abstractions/CHANGELOG.md @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Unless otherwise noted, all changes made by [@jeremyknight-me](https://github.com/jeremyknight-me). +## 2.0.0 + +### Added + +- Added support for .NET 9. + +### Removed + +- Removed support for .NET 6. + ## 1.1.0 ### Added diff --git a/src/JK.Common.Abstractions/JK.Common.Abstractions.csproj b/src/JK.Common.Abstractions/JK.Common.Abstractions.csproj index e343f89..09dd56c 100644 --- a/src/JK.Common.Abstractions/JK.Common.Abstractions.csproj +++ b/src/JK.Common.Abstractions/JK.Common.Abstractions.csproj @@ -1,10 +1,10 @@  - net8.0;net6.0;netstandard2.0 + net9.0;net8.0;netstandard2.0 true False - 1.1.0 + 2.0.0 Abstractions used in utility libraries which allows for less dependencies to be shared across projects. README.md diff --git a/src/JK.Common.Data.Sql.Tests/Extensions/Parameters/ParameterAssertHelper.cs b/src/JK.Common.Data.Sql.Tests/Extensions/Parameters/ParameterAssertHelper.cs index a6e0596..d66b39b 100644 --- a/src/JK.Common.Data.Sql.Tests/Extensions/Parameters/ParameterAssertHelper.cs +++ b/src/JK.Common.Data.Sql.Tests/Extensions/Parameters/ParameterAssertHelper.cs @@ -15,5 +15,5 @@ internal static SqlParameter AssertSingleAndReturn(SqlCommand command, string ex var parameter = command.Parameters[0]; Assert.Equal(expectedName, parameter.ParameterName); return parameter; - } + } } diff --git a/src/JK.Common.Data.Sql.Tests/JK.Common.Data.Sql.Tests.csproj b/src/JK.Common.Data.Sql.Tests/JK.Common.Data.Sql.Tests.csproj index 3d09b02..673c2ad 100644 --- a/src/JK.Common.Data.Sql.Tests/JK.Common.Data.Sql.Tests.csproj +++ b/src/JK.Common.Data.Sql.Tests/JK.Common.Data.Sql.Tests.csproj @@ -1,7 +1,7 @@  - net8.0;net6.0;net48 + net9.0;net8.0;net48 false diff --git a/src/JK.Common.Data.Sql/CHANGELOG.md b/src/JK.Common.Data.Sql/CHANGELOG.md index f2e5d2a..b355945 100644 --- a/src/JK.Common.Data.Sql/CHANGELOG.md +++ b/src/JK.Common.Data.Sql/CHANGELOG.md @@ -7,12 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Unless otherwise noted, all changes made by [@jeremyknight-me](https://github.com/jeremyknight-me). -## Unreleased +## 6.0.0 + +## Added + +- Added support for .NET 9. ### Changed - Upgraded `Microsoft.Data.SqlClient` to v5.2.0 +### Removed + +- Removed support for .NET 6. + ## 5.2.0 ### Added diff --git a/src/JK.Common.Data.Sql/Extensions/SqlBulkCopyExtensions.cs b/src/JK.Common.Data.Sql/Extensions/SqlBulkCopyExtensions.cs index a88a8b9..1b2bf9c 100644 --- a/src/JK.Common.Data.Sql/Extensions/SqlBulkCopyExtensions.cs +++ b/src/JK.Common.Data.Sql/Extensions/SqlBulkCopyExtensions.cs @@ -4,31 +4,30 @@ using System.Text.RegularExpressions; using Microsoft.Data.SqlClient; -namespace JK.Common.Data.Sql.Extensions +namespace JK.Common.Data.Sql.Extensions; + +public static class SqlBulkCopyExtensions { - public static class SqlBulkCopyExtensions + public static void ThrowIfColumnLengthException(this SqlBulkCopy bulk, SqlException ex) { - public static void ThrowIfColumnLengthException(this SqlBulkCopy bulk, SqlException ex) + if (ex.Message.Contains("Received an invalid column length from the bcp client for colid")) { - if (ex.Message.Contains("Received an invalid column length from the bcp client for colid")) - { - var pattern = @"\d+"; - var match = Regex.Match(ex.Message.ToString(), pattern); - var index = Convert.ToInt32(match.Value) - 1; - var sortedColumnsField = typeof(SqlBulkCopy).GetField("_sortedColumnMappings", BindingFlags.NonPublic | BindingFlags.Instance); - var sortedColumns = sortedColumnsField.GetValue(bulk); - var itemsField = sortedColumns.GetType().GetField("_items", BindingFlags.NonPublic | BindingFlags.Instance); - var items = (object[])itemsField.GetValue(sortedColumns); - var itemdata = items[index].GetType().GetField("_metadata", BindingFlags.NonPublic | BindingFlags.Instance); - var metadata = itemdata.GetValue(items[index]); - var column = metadata.GetType() - .GetField("column", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) - .GetValue(metadata); - var length = metadata.GetType() - .GetField("length", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) - .GetValue(metadata); - throw new DataException($"Column '{column}' contains data with a length greater than {length}", ex); - } + var pattern = @"\d+"; + var match = Regex.Match(ex.Message.ToString(), pattern); + var index = Convert.ToInt32(match.Value) - 1; + var sortedColumnsField = typeof(SqlBulkCopy).GetField("_sortedColumnMappings", BindingFlags.NonPublic | BindingFlags.Instance); + var sortedColumns = sortedColumnsField.GetValue(bulk); + var itemsField = sortedColumns.GetType().GetField("_items", BindingFlags.NonPublic | BindingFlags.Instance); + var items = (object[])itemsField.GetValue(sortedColumns); + var itemdata = items[index].GetType().GetField("_metadata", BindingFlags.NonPublic | BindingFlags.Instance); + var metadata = itemdata.GetValue(items[index]); + var column = metadata.GetType() + .GetField("column", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) + .GetValue(metadata); + var length = metadata.GetType() + .GetField("length", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) + .GetValue(metadata); + throw new DataException($"Column '{column}' contains data with a length greater than {length}", ex); } } } diff --git a/src/JK.Common.Data.Sql/IsExternalInit.cs b/src/JK.Common.Data.Sql/IsExternalInit.cs index 651aa19..892d681 100644 --- a/src/JK.Common.Data.Sql/IsExternalInit.cs +++ b/src/JK.Common.Data.Sql/IsExternalInit.cs @@ -2,12 +2,11 @@ using System.ComponentModel; -namespace System.Runtime.CompilerServices +namespace System.Runtime.CompilerServices; + +[EditorBrowsable(EditorBrowsableState.Never)] +internal static class IsExternalInit { - [EditorBrowsable(EditorBrowsableState.Never)] - internal static class IsExternalInit - { - } } #endif diff --git a/src/JK.Common.Data.Sql/JK.Common.Data.Sql.csproj b/src/JK.Common.Data.Sql/JK.Common.Data.Sql.csproj index ef263b3..cded144 100644 --- a/src/JK.Common.Data.Sql/JK.Common.Data.Sql.csproj +++ b/src/JK.Common.Data.Sql/JK.Common.Data.Sql.csproj @@ -1,8 +1,8 @@  - net8.0;net6.0;netstandard2.0 - 5.2.0 + net9.0;net8.0;netstandard2.0 + 6.0.0 A utility library containing extensions to System.Data.SqlClient diff --git a/src/JK.Common.Data.Sql/SqlBulkInsertOperation.cs b/src/JK.Common.Data.Sql/SqlBulkInsertOperation.cs index 8a6be67..dc3ef6f 100644 --- a/src/JK.Common.Data.Sql/SqlBulkInsertOperation.cs +++ b/src/JK.Common.Data.Sql/SqlBulkInsertOperation.cs @@ -8,7 +8,7 @@ namespace JK.Common.Data.Sql; -public class SqlBulkInsertOperation +public class SqlBulkInsertOperation { private readonly IAdoConnectionFactory connectionFactory; diff --git a/src/JK.Common.EntityFrameworkCore.SqlServer/CHANGELOG.md b/src/JK.Common.EntityFrameworkCore.SqlServer/CHANGELOG.md index af8bdf5..3a71c92 100644 --- a/src/JK.Common.EntityFrameworkCore.SqlServer/CHANGELOG.md +++ b/src/JK.Common.EntityFrameworkCore.SqlServer/CHANGELOG.md @@ -7,7 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Unless otherwise noted, all changes made by [@jeremyknight-me](https://github.com/jeremyknight-me). -## Unreleased +## 4.0.0 + +## Added + +- Added support for .NET 9. ### Changed @@ -15,7 +19,7 @@ Unless otherwise noted, all changes made by [@jeremyknight-me](https://github.co ### Removed -- Support for .NET Standard 2.0 +- Removed support for .NET Standard 2.0 and .NET 6 ## 3.2.0 diff --git a/src/JK.Common.EntityFrameworkCore.SqlServer/Extensions/ModelConfigurationBuilderExtensions.cs b/src/JK.Common.EntityFrameworkCore.SqlServer/Extensions/ModelConfigurationBuilderExtensions.cs index f776846..b154f81 100644 --- a/src/JK.Common.EntityFrameworkCore.SqlServer/Extensions/ModelConfigurationBuilderExtensions.cs +++ b/src/JK.Common.EntityFrameworkCore.SqlServer/Extensions/ModelConfigurationBuilderExtensions.cs @@ -1,6 +1,4 @@ -#if NET6_0_OR_GREATER - -using System; +using System; namespace JK.Common.EntityFrameworkCore.SqlServer.Extensions; @@ -12,5 +10,3 @@ public static void ApplyConventionPreferences(this ModelConfigurationBuilder con configurationBuilder.Properties().HavePrecision(2); } } - -#endif diff --git a/src/JK.Common.EntityFrameworkCore.SqlServer/JK.Common.EntityFrameworkCore.SqlServer.csproj b/src/JK.Common.EntityFrameworkCore.SqlServer/JK.Common.EntityFrameworkCore.SqlServer.csproj index 027c2a9..0f64d35 100644 --- a/src/JK.Common.EntityFrameworkCore.SqlServer/JK.Common.EntityFrameworkCore.SqlServer.csproj +++ b/src/JK.Common.EntityFrameworkCore.SqlServer/JK.Common.EntityFrameworkCore.SqlServer.csproj @@ -1,19 +1,15 @@  - net8.0;net6.0 + net9.0;net8.0 true false - 3.2.0 + 4.0.0 A utility library containing extensions to Microsoft.EntityFrameworkCore.SqlServer - - - - - - + + diff --git a/src/JK.Common.EntityFrameworkCore.Tests/JK.Common.EntityFrameworkCore.Tests.csproj b/src/JK.Common.EntityFrameworkCore.Tests/JK.Common.EntityFrameworkCore.Tests.csproj index 00bb124..fcf4587 100644 --- a/src/JK.Common.EntityFrameworkCore.Tests/JK.Common.EntityFrameworkCore.Tests.csproj +++ b/src/JK.Common.EntityFrameworkCore.Tests/JK.Common.EntityFrameworkCore.Tests.csproj @@ -1,13 +1,13 @@  - net8.0;net6.0 + net9.0;net8.0 false - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -18,14 +18,9 @@ - - - - - - - - + + + diff --git a/src/JK.Common.EntityFrameworkCore/CHANGELOG.md b/src/JK.Common.EntityFrameworkCore/CHANGELOG.md index c2471b5..9b009da 100644 --- a/src/JK.Common.EntityFrameworkCore/CHANGELOG.md +++ b/src/JK.Common.EntityFrameworkCore/CHANGELOG.md @@ -7,10 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Unless otherwise noted, all changes made by [@jeremyknight-me](https://github.com/jeremyknight-me). -## Unreleased +## 5.0.0 ### Added +- Added support for .NET 9. - Added `AuditableSaveChangesInterceptor` ### Changed @@ -19,7 +20,7 @@ Unless otherwise noted, all changes made by [@jeremyknight-me](https://github.co ### Removed -- Removed support for .NET Standard 2.0 +- Removed support for .NET Standard 2.0 and .NET 6 - Removed `ChangeTrackerExtensions` in favor of interceptor ## 4.1.0 diff --git a/src/JK.Common.EntityFrameworkCore/JK.Common.EntityFrameworkCore.csproj b/src/JK.Common.EntityFrameworkCore/JK.Common.EntityFrameworkCore.csproj index dd6b93f..3b73331 100644 --- a/src/JK.Common.EntityFrameworkCore/JK.Common.EntityFrameworkCore.csproj +++ b/src/JK.Common.EntityFrameworkCore/JK.Common.EntityFrameworkCore.csproj @@ -1,24 +1,19 @@  - net8.0;net6.0 + net9.0;net8.0 true false A utility library containing extensions to Microsoft.EntityFrameworkCore - 4.1.0.0 - 4.1.0 + 5.0.0 - + - - - - - - + + diff --git a/src/JK.Common.FluentValidation.Tests/JK.Common.FluentValidation.Tests.csproj b/src/JK.Common.FluentValidation.Tests/JK.Common.FluentValidation.Tests.csproj index 2561fcb..8081a0a 100644 --- a/src/JK.Common.FluentValidation.Tests/JK.Common.FluentValidation.Tests.csproj +++ b/src/JK.Common.FluentValidation.Tests/JK.Common.FluentValidation.Tests.csproj @@ -1,7 +1,7 @@  - net8.0;net6.0 + net9.0;net8.0 false diff --git a/src/JK.Common.FluentValidation/CHANGELOG.md b/src/JK.Common.FluentValidation/CHANGELOG.md index 4a4bec7..066ce51 100644 --- a/src/JK.Common.FluentValidation/CHANGELOG.md +++ b/src/JK.Common.FluentValidation/CHANGELOG.md @@ -7,9 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Unless otherwise noted, all changes made by [@jeremyknight-me](https://github.com/jeremyknight-me). -## Unreleased +## 4.0.0 -Nothing at this time. +## Added + +- Added support for .NET 9. + +### Removed + +- Removed support for .NET Standard 2.0, .NET 6, and .NET 7 ## 3.1.0 diff --git a/src/JK.Common.FluentValidation/JK.Common.FluentValidation.csproj b/src/JK.Common.FluentValidation/JK.Common.FluentValidation.csproj index a2e3d80..d75b77f 100644 --- a/src/JK.Common.FluentValidation/JK.Common.FluentValidation.csproj +++ b/src/JK.Common.FluentValidation/JK.Common.FluentValidation.csproj @@ -1,10 +1,10 @@  - net8.0;net6.0;netstandard2.0 + net9.0;net8.0;netstandard2.0 true false - 3.1.0 + 4.0.0 A utility library containing extensions to FluentValidation diff --git a/src/JK.Common.Tests/Extensions/StringExtensionsTest.cs b/src/JK.Common.Tests/Extensions/StringExtensionsTest.cs index 231fc9e..77442f8 100644 --- a/src/JK.Common.Tests/Extensions/StringExtensionsTest.cs +++ b/src/JK.Common.Tests/Extensions/StringExtensionsTest.cs @@ -6,7 +6,6 @@ namespace JK.Common.Tests.Extensions; public class StringExtensionsTest { - [Fact] public void Parse_Int() diff --git a/src/JK.Common.Tests/JK.Common.Tests.csproj b/src/JK.Common.Tests/JK.Common.Tests.csproj index 43f999a..c408c62 100644 --- a/src/JK.Common.Tests/JK.Common.Tests.csproj +++ b/src/JK.Common.Tests/JK.Common.Tests.csproj @@ -1,7 +1,7 @@  - net8.0;net6.0;net48 + net9.0;net8.0;net48 true false diff --git a/src/JK.Common.Tests/Sorting/InsertionSortTests.cs b/src/JK.Common.Tests/Sorting/InsertionSortTests.cs index 88a5382..d9934ab 100644 --- a/src/JK.Common.Tests/Sorting/InsertionSortTests.cs +++ b/src/JK.Common.Tests/Sorting/InsertionSortTests.cs @@ -1,41 +1,40 @@ using System.Collections.Generic; using JK.Common.Sorting; -namespace JK.Common.Tests.Sorting +namespace JK.Common.Tests.Sorting; + +public class InsertionSortTests { - public class InsertionSortTests + [Fact] + public void Sort_IntArray_Test() { - [Fact] - public void Sort_IntArray_Test() - { - var original = new int[] { 2, 5, -4, 11, 0, 18, 22, 67, 51, 6 }; - InsertionSort.Sort(original); - Assert.Collection(original, - i => Assert.Equal(-4, i), - i => Assert.Equal(0, i), - i => Assert.Equal(2, i), - i => Assert.Equal(5, i), - i => Assert.Equal(6, i), - i => Assert.Equal(11, i), - i => Assert.Equal(18, i), - i => Assert.Equal(22, i), - i => Assert.Equal(51, i), - i => Assert.Equal(67, i) - ); - } + var original = new int[] { 2, 5, -4, 11, 0, 18, 22, 67, 51, 6 }; + InsertionSort.Sort(original); + Assert.Collection(original, + i => Assert.Equal(-4, i), + i => Assert.Equal(0, i), + i => Assert.Equal(2, i), + i => Assert.Equal(5, i), + i => Assert.Equal(6, i), + i => Assert.Equal(11, i), + i => Assert.Equal(18, i), + i => Assert.Equal(22, i), + i => Assert.Equal(51, i), + i => Assert.Equal(67, i) + ); + } - [Fact] - public void Sort_StringList_Test() - { - var original = new List { "i", "g", "e", "c", "f" }; - InsertionSort.Sort(original); - Assert.Collection(original, - i => Assert.Equal("c", i), - i => Assert.Equal("e", i), - i => Assert.Equal("f", i), - i => Assert.Equal("g", i), - i => Assert.Equal("i", i) - ); - } + [Fact] + public void Sort_StringList_Test() + { + var original = new List { "i", "g", "e", "c", "f" }; + InsertionSort.Sort(original); + Assert.Collection(original, + i => Assert.Equal("c", i), + i => Assert.Equal("e", i), + i => Assert.Equal("f", i), + i => Assert.Equal("g", i), + i => Assert.Equal("i", i) + ); } } diff --git a/src/JK.Common.Tests/Sorting/SelectionSortTests.cs b/src/JK.Common.Tests/Sorting/SelectionSortTests.cs index 59c5013..eacb19b 100644 --- a/src/JK.Common.Tests/Sorting/SelectionSortTests.cs +++ b/src/JK.Common.Tests/Sorting/SelectionSortTests.cs @@ -1,41 +1,40 @@ using System.Collections.Generic; using JK.Common.Sorting; -namespace JK.Common.Tests.Sorting +namespace JK.Common.Tests.Sorting; + +public class SelectionSortTests { - public class SelectionSortTests + [Fact] + public void Sort_IntArray_Test() { - [Fact] - public void Sort_IntArray_Test() - { - var original = new int[] { 2, 5, -4, 11, 0, 18, 22, 67, 51, 6 }; - SelectionSort.Sort(original); - Assert.Collection(original, - i => Assert.Equal(-4, i), - i => Assert.Equal(0, i), - i => Assert.Equal(2, i), - i => Assert.Equal(5, i), - i => Assert.Equal(6, i), - i => Assert.Equal(11, i), - i => Assert.Equal(18, i), - i => Assert.Equal(22, i), - i => Assert.Equal(51, i), - i => Assert.Equal(67, i) - ); - } + var original = new int[] { 2, 5, -4, 11, 0, 18, 22, 67, 51, 6 }; + SelectionSort.Sort(original); + Assert.Collection(original, + i => Assert.Equal(-4, i), + i => Assert.Equal(0, i), + i => Assert.Equal(2, i), + i => Assert.Equal(5, i), + i => Assert.Equal(6, i), + i => Assert.Equal(11, i), + i => Assert.Equal(18, i), + i => Assert.Equal(22, i), + i => Assert.Equal(51, i), + i => Assert.Equal(67, i) + ); + } - [Fact] - public void Sort_StringList_Test() - { - var original = new List { "i", "g", "e", "c", "f" }; - SelectionSort.Sort(original); - Assert.Collection(original, - i => Assert.Equal("c", i), - i => Assert.Equal("e", i), - i => Assert.Equal("f", i), - i => Assert.Equal("g", i), - i => Assert.Equal("i", i) - ); - } + [Fact] + public void Sort_StringList_Test() + { + var original = new List { "i", "g", "e", "c", "f" }; + SelectionSort.Sort(original); + Assert.Collection(original, + i => Assert.Equal("c", i), + i => Assert.Equal("e", i), + i => Assert.Equal("f", i), + i => Assert.Equal("g", i), + i => Assert.Equal("i", i) + ); } } diff --git a/src/JK.Common.Tests/TypeHelpers/DecimalHelperTests.cs b/src/JK.Common.Tests/TypeHelpers/DecimalHelperTests.cs index bffa7a3..6937ef0 100644 --- a/src/JK.Common.Tests/TypeHelpers/DecimalHelperTests.cs +++ b/src/JK.Common.Tests/TypeHelpers/DecimalHelperTests.cs @@ -1,27 +1,26 @@ using JK.Common.TypeHelpers; -namespace JK.Common.Tests.TypeHelpers +namespace JK.Common.Tests.TypeHelpers; + +public class DecimalHelperTests { - public class DecimalHelperTests + [Theory] + [InlineData(0, 1.0)] + [InlineData(0.1, 1.1)] + [InlineData(0.25, 1.25)] + public void GetDecimalPart_Theories(decimal expected, decimal value) { - [Theory] - [InlineData(0, 1.0)] - [InlineData(0.1, 1.1)] - [InlineData(0.25, 1.25)] - public void GetDecimalPart_Theories(decimal expected, decimal value) - { - var actual = DecimalHelper.GetDecimalPart(value); - Assert.Equal(expected, actual); - } + var actual = DecimalHelper.GetDecimalPart(value); + Assert.Equal(expected, actual); + } - [Theory] - [InlineData(0, 0.12)] - [InlineData(1, 1.54)] - [InlineData(25, 25.75)] - public void GetWholePart_Theories(decimal expected, decimal value) - { - var actual = DecimalHelper.GetWholePart(value); - Assert.Equal(expected, actual); - } + [Theory] + [InlineData(0, 0.12)] + [InlineData(1, 1.54)] + [InlineData(25, 25.75)] + public void GetWholePart_Theories(decimal expected, decimal value) + { + var actual = DecimalHelper.GetWholePart(value); + Assert.Equal(expected, actual); } } diff --git a/src/JK.Common.Tests/TypeHelpers/StringHelperTests/Slice.cs b/src/JK.Common.Tests/TypeHelpers/StringHelperTests/Slice.cs index 517aaeb..90b95eb 100644 --- a/src/JK.Common.Tests/TypeHelpers/StringHelperTests/Slice.cs +++ b/src/JK.Common.Tests/TypeHelpers/StringHelperTests/Slice.cs @@ -20,7 +20,7 @@ public void Slice_StartLength_Test() const string s = "Bacon ipsum dolor amet meatball"; var actual = StringHelper.Slice(s, 0, 5); Assert.Equal("Bacon", actual.ToString()); - } + } } #endif diff --git a/src/JK.Common/CHANGELOG.md b/src/JK.Common/CHANGELOG.md index 245ac61..d193661 100644 --- a/src/JK.Common/CHANGELOG.md +++ b/src/JK.Common/CHANGELOG.md @@ -7,10 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Unless otherwise noted, all changes made by [@jeremyknight-me](https://github.com/jeremyknight-me). -## Unreleased +## 6.0.0 ## Added +- Added support for .NET 9. - `IsNullable` helper method in `TypeHelper` ## Changed @@ -18,6 +19,10 @@ Unless otherwise noted, all changes made by [@jeremyknight-me](https://github.co - `IsNullable` to `IsNullableT` int `TypeHelper`. - Moved `ServiceLocator` folder to `Patterns` folder. +### Removed + +- Removed support for .NET 6. + ## 5.2.0 ### Added diff --git a/src/JK.Common/Enumerations/DistanceUnitAbbreviationFactory.cs b/src/JK.Common/Enumerations/DistanceUnitAbbreviationFactory.cs index 2a4c128..4c93cbd 100644 --- a/src/JK.Common/Enumerations/DistanceUnitAbbreviationFactory.cs +++ b/src/JK.Common/Enumerations/DistanceUnitAbbreviationFactory.cs @@ -1,15 +1,14 @@ -namespace JK.Common.Enumerations +namespace JK.Common.Enumerations; + +public static class DistanceUnitAbbreviationFactory { - public static class DistanceUnitAbbreviationFactory - { - public static string Make(DistanceUnit distanceUnit) - => distanceUnit switch - { - DistanceUnit.Feet => "ft", - DistanceUnit.Inches => "in", - DistanceUnit.Meters => "m", - DistanceUnit.Centimeters => "cm", - _ => null, - }; - } + public static string Make(DistanceUnit distanceUnit) + => distanceUnit switch + { + DistanceUnit.Feet => "ft", + DistanceUnit.Inches => "in", + DistanceUnit.Meters => "m", + DistanceUnit.Centimeters => "cm", + _ => null, + }; } diff --git a/src/JK.Common/Extensions/TypeExtensions.cs b/src/JK.Common/Extensions/TypeExtensions.cs index 4657057..aad5e48 100644 --- a/src/JK.Common/Extensions/TypeExtensions.cs +++ b/src/JK.Common/Extensions/TypeExtensions.cs @@ -34,6 +34,7 @@ public static Type GetTypeFromEntity(this Type type) { type = type.BaseType; } + return type; } diff --git a/src/JK.Common/IsExternalInit.cs b/src/JK.Common/IsExternalInit.cs index 651aa19..892d681 100644 --- a/src/JK.Common/IsExternalInit.cs +++ b/src/JK.Common/IsExternalInit.cs @@ -2,12 +2,11 @@ using System.ComponentModel; -namespace System.Runtime.CompilerServices +namespace System.Runtime.CompilerServices; + +[EditorBrowsable(EditorBrowsableState.Never)] +internal static class IsExternalInit { - [EditorBrowsable(EditorBrowsableState.Never)] - internal static class IsExternalInit - { - } } #endif diff --git a/src/JK.Common/JK.Common.csproj b/src/JK.Common/JK.Common.csproj index 625ef7d..d837692 100644 --- a/src/JK.Common/JK.Common.csproj +++ b/src/JK.Common/JK.Common.csproj @@ -1,10 +1,10 @@  - net8.0;net6.0;netstandard2.0 + net9.0;net8.0;netstandard2.0 true False - 5.2.0 + 6.0.0 A utility library containing boilerplate code, extension methods, new classes, and/or improvements to existing classes. README.md diff --git a/src/JK.Common/Patterns/Singleton/LockedSingleton.cs b/src/JK.Common/Patterns/Singleton/LockedSingleton.cs index e77c5d4..9c5c691 100644 --- a/src/JK.Common/Patterns/Singleton/LockedSingleton.cs +++ b/src/JK.Common/Patterns/Singleton/LockedSingleton.cs @@ -19,6 +19,7 @@ public static LockedSingleton Instance { instance = new LockedSingleton(); } + return instance; } } diff --git a/src/JK.Common/RangePolyfill.cs b/src/JK.Common/RangePolyfill.cs index 19084eb..2d1ec96 100644 --- a/src/JK.Common/RangePolyfill.cs +++ b/src/JK.Common/RangePolyfill.cs @@ -34,15 +34,19 @@ public Index(int value, bool fromEnd = false) } if (fromEnd) - _value = ~value; + { + this._value = ~value; + } else - _value = value; + { + this._value = value; + } } // The following private constructors mainly created for perf reason to avoid the checks private Index(int value) { - _value = value; + this._value = value; } /// Create an Index pointing at first element. @@ -82,19 +86,19 @@ public int Value { get { - if (_value < 0) + if (this._value < 0) { - return ~_value; + return ~this._value; } else { - return _value; + return this._value; } } } /// Indicates whether the index is from the start or the end. - public bool IsFromEnd => _value < 0; + public bool IsFromEnd => this._value < 0; /// Calculate the offset from the start using the giving collection length. /// The length of the collection that the Index will be used with. length has to be a positive value @@ -107,8 +111,8 @@ public int Value [MethodImpl(MethodImplOptions.AggressiveInlining)] public int GetOffset(int length) { - var offset = _value; - if (IsFromEnd) + var offset = this._value; + if (this.IsFromEnd) { // offset = length - (~value) // offset = length + (~(~value) + 1) @@ -116,19 +120,20 @@ public int GetOffset(int length) offset += length + 1; } + return offset; } /// Indicates whether the current Index object is equal to another object of the same type. /// An object to compare with this object - public override bool Equals(object? value) => value is Index && _value == ((Index)value)._value; + public override bool Equals(object? value) => value is Index && this._value == ((Index)value)._value; /// Indicates whether the current Index object is equal to another Index object. /// An object to compare with this object - public bool Equals(Index other) => _value == other._value; + public bool Equals(Index other) => this._value == other._value; /// Returns the hash code for this instance. - public override int GetHashCode() => _value; + public override int GetHashCode() => this._value; /// Converts integer number to an Index. public static implicit operator Index(int value) => FromStart(value); @@ -136,10 +141,12 @@ public int GetOffset(int length) /// Converts the value of the current Index object to its equivalent string representation. public override string ToString() { - if (IsFromEnd) - return "^" + ((uint)Value).ToString(); + if (this.IsFromEnd) + { + return "^" + ((uint)this.Value).ToString(); + } - return ((uint)Value).ToString(); + return ((uint)this.Value).ToString(); } } @@ -171,31 +178,31 @@ public Index End /// Represent the exclusive end index of the range. public Range(Index start, Index end) { - Start = start; - End = end; + this.Start = start; + this.End = end; } /// Indicates whether the current Range object is equal to another object of the same type. /// An object to compare with this object public override bool Equals(object? value) => value is Range r && - r.Start.Equals(Start) && - r.End.Equals(End); + r.Start.Equals(this.Start) && + r.End.Equals(this.End); /// Indicates whether the current Range object is equal to another Range object. /// An object to compare with this object - public bool Equals(Range other) => other.Start.Equals(Start) && other.End.Equals(End); + public bool Equals(Range other) => other.Start.Equals(this.Start) && other.End.Equals(this.End); /// Returns the hash code for this instance. public override int GetHashCode() { - return Start.GetHashCode() * 31 + End.GetHashCode(); + return this.Start.GetHashCode() * 31 + this.End.GetHashCode(); } /// Converts the value of the current Range object to its equivalent string representation. public override string ToString() { - return Start + ".." + End; + return this.Start + ".." + this.End; } /// Create a Range object starting from start index to the end of the collection. @@ -218,18 +225,26 @@ public override string ToString() public (int Offset, int Length) GetOffsetAndLength(int length) { int start; - var startIndex = Start; + var startIndex = this.Start; if (startIndex.IsFromEnd) + { start = length - startIndex.Value; + } else + { start = startIndex.Value; + } int end; - var endIndex = End; + var endIndex = this.End; if (endIndex.IsFromEnd) + { end = length - endIndex.Value; + } else + { end = endIndex.Value; + } if ((uint)end > (uint)length || (uint)start > (uint)end) { @@ -281,5 +296,4 @@ public static T[] GetSubArray(T[] array, Range range) } } - #endif diff --git a/src/JK.Common/Sorting/BubbleSort.cs b/src/JK.Common/Sorting/BubbleSort.cs index dd0ccc4..c70d8a6 100644 --- a/src/JK.Common/Sorting/BubbleSort.cs +++ b/src/JK.Common/Sorting/BubbleSort.cs @@ -1,22 +1,19 @@ using System; using System.Collections.Generic; -namespace JK.Common.Sorting +namespace JK.Common.Sorting; + +public static class BubbleSort { - public static class BubbleSort + public static void Sort(IList data) where T : IComparable, IComparable { - public static void Sort(IList data) where T : IComparable, IComparable + for (var a = 1; a < data.Count; a++) { - for (var a = 1; a < data.Count; a++) + for (var b = data.Count - 1; b >= a; b--) { - for (var b = data.Count - 1; b >= a; b--) + if (data[b].CompareTo(data[b - 1]) < 0) { - if (data[b].CompareTo(data[b - 1]) < 0) - { - var t = data[b - 1]; - data[b - 1] = data[b]; - data[b] = t; - } + (data[b], data[b - 1]) = (data[b - 1], data[b]); } } } diff --git a/src/JK.Common/Sorting/HeapSort.cs b/src/JK.Common/Sorting/HeapSort.cs index 937fda6..762ab05 100644 --- a/src/JK.Common/Sorting/HeapSort.cs +++ b/src/JK.Common/Sorting/HeapSort.cs @@ -1,38 +1,36 @@ using System; using System.Collections.Generic; -namespace JK.Common.Sorting +namespace JK.Common.Sorting; + +public static class HeapSort { - public static class HeapSort + public static void Sort(IList list) where T : IComparable, IComparable { - public static void Sort(IList list) where T : IComparable, IComparable + MakeHeap(list, list.Count); + for (var i = list.Count - 1; i > 0; i--) { - MakeHeap(list, list.Count); - for (var i = list.Count - 1; i > 0; i--) - { - var value = list[i]; - list[i] = list[0]; - list[0] = value; - MakeHeap(list, i); - } + (list[0], list[i]) = (list[i], list[0]); + MakeHeap(list, i); } + } - private static void MakeHeap(IList list, int c) - where T : IComparable, IComparable + private static void MakeHeap(IList list, int c) + where T : IComparable, IComparable + { + for (var i = 1; i < c; i++) { - for (var i = 1; i < c; i++) + var value = list[i]; + var s = i; + var f = (s - 1) / 2; + while (s > 0 && list[f].CompareTo(value) < 0) { - var value = list[i]; - var s = i; - var f = (s - 1) / 2; - while (s > 0 && list[f].CompareTo(value) < 0) - { - list[s] = list[f]; - s = f; - f = (s - 1) / 2; - } - list[s] = value; + list[s] = list[f]; + s = f; + f = (s - 1) / 2; } + + list[s] = value; } } } diff --git a/src/JK.Common/Sorting/MergeSort.cs b/src/JK.Common/Sorting/MergeSort.cs index 5f8a66b..272638f 100644 --- a/src/JK.Common/Sorting/MergeSort.cs +++ b/src/JK.Common/Sorting/MergeSort.cs @@ -1,61 +1,60 @@ using System; using System.Collections.Generic; -namespace JK.Common.Sorting +namespace JK.Common.Sorting; + +public static class MergeSort { - public static class MergeSort + public static void Sort(IList list) where T : IComparable, IComparable + => Sort(list, 0, list.Count - 1); + + private static void Sort(IList list, int low, int high) + where T : IComparable, IComparable { - public static void Sort(IList list) where T : IComparable, IComparable - => Sort(list, 0, list.Count - 1); + if (low < high) + { + var mid = (low + high) / 2; + Sort(list, low, mid); + Sort(list, mid + 1, high); + Merge(list, low, mid, high); + } + } - private static void Sort(IList list, int low, int high) - where T : IComparable, IComparable + private static void Merge(IList list, int low, int mid, int high) + where T : IComparable, IComparable + { + var h = low; + var i = low; + var j = mid + 1; + var temp = new List(new T[list.Count]); + while (h <= mid && j <= high) { - if (low < high) - { - var mid = (low + high) / 2; - Sort(list, low, mid); - Sort(list, mid + 1, high); - Merge(list, low, mid, high); - } + temp[i] = list[h].CompareTo(list[j]) <= 0 + ? list[h++] + : list[j++]; + i++; } - private static void Merge(IList list, int low, int mid, int high) - where T : IComparable, IComparable + if (h > mid) { - var h = low; - var i = low; - var j = mid + 1; - var temp = new List(new T[list.Count]); - while (h <= mid && j <= high) + for (var k = j; k <= high; k++) { - temp[i] = list[h].CompareTo(list[j]) <= 0 - ? list[h++] - : list[j++]; + temp[i] = list[k]; i++; } - - if (h > mid) - { - for (var k = j; k <= high; k++) - { - temp[i] = list[k]; - i++; - } - } - else + } + else + { + for (var k = h; k <= mid; k++) { - for (var k = h; k <= mid; k++) - { - temp[i] = list[k]; - i++; - } + temp[i] = list[k]; + i++; } + } - for (var k = low; k <= high; k++) - { - list[k] = temp[k]; - } + for (var k = low; k <= high; k++) + { + list[k] = temp[k]; } } } diff --git a/src/JK.Common/Sorting/QuickSort.cs b/src/JK.Common/Sorting/QuickSort.cs index c43bd64..85f0f00 100644 --- a/src/JK.Common/Sorting/QuickSort.cs +++ b/src/JK.Common/Sorting/QuickSort.cs @@ -32,6 +32,7 @@ private static int Partition(IList list, int low, int high) { break; } + high--; highValue = list[high]; } @@ -44,6 +45,7 @@ private static int Partition(IList list, int low, int high) { break; } + low++; lowValue = list[low]; } diff --git a/src/JK.Common/Sorting/ShellSort.cs b/src/JK.Common/Sorting/ShellSort.cs index 7036305..0b365b8 100644 --- a/src/JK.Common/Sorting/ShellSort.cs +++ b/src/JK.Common/Sorting/ShellSort.cs @@ -20,6 +20,7 @@ public static void Sort(IList list) where T : IComparable, IComparable list[j] = list[j - gap]; j -= gap; } + list[j] = temp; }