diff --git a/.github/workflows/dotnet-codeql.yml b/.github/workflows/dotnet-codeql.yml index ed0d191..ba9dc56 100644 --- a/.github/workflows/dotnet-codeql.yml +++ b/.github/workflows/dotnet-codeql.yml @@ -36,8 +36,8 @@ jobs: uses: actions/setup-dotnet@v3 with: dotnet-version: | - 6.0.x 7.0.x + 8.0.x # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 3aaf2f8..d683200 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -6,7 +6,7 @@ on: pull_request: branches: [ main ] release: - types: [ published ] + types: [ published ] jobs: build: @@ -18,8 +18,8 @@ jobs: uses: actions/setup-dotnet@v3 with: dotnet-version: | - 6.0.x 7.0.x + 8.0.x - name: Install dependencies run: dotnet restore diff --git a/Directory.Build.props b/Directory.Build.props index e44f3fe..21f6da9 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,8 +1,8 @@ - netstandard2.0;net7.0 - net6.0;net7.0 - net7.0 + net7.0;net8.0 + net7.0;net8.0 + net8.0 false @@ -10,6 +10,8 @@ true + + latest diff --git a/Directory.Packages.props b/Directory.Packages.props index 3fa8832..06e540d 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -5,10 +5,6 @@ - - - - diff --git a/sample/WeatherForecastWebApi/Controllers/WeatherForecastController.cs b/sample/WeatherForecastWebApi/Controllers/WeatherForecastController.cs index 0648880..87cbe4d 100644 --- a/sample/WeatherForecastWebApi/Controllers/WeatherForecastController.cs +++ b/sample/WeatherForecastWebApi/Controllers/WeatherForecastController.cs @@ -6,10 +6,7 @@ namespace WeatherForecastWebApi.Controllers; [Route("[controller]")] public class WeatherForecastController : ControllerBase { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; + private static readonly string[] Summaries = ["Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"]; public WeatherForecastController() { diff --git a/src/ZCS.DataContractResolver/DataContractResolver.cs b/src/ZCS.DataContractResolver/DataContractResolver.cs index e43e0f0..e642e2b 100644 --- a/src/ZCS.DataContractResolver/DataContractResolver.cs +++ b/src/ZCS.DataContractResolver/DataContractResolver.cs @@ -40,13 +40,7 @@ private static bool IsNullOrDefault(object obj) return false; } -#if NET5_0_OR_GREATER - return RuntimeHelpers -#else - return FormatterServices -#endif - .GetUninitializedObject(type) - .Equals(obj); + return RuntimeHelpers.GetUninitializedObject(type).Equals(obj); } private static IEnumerable EnumerateFieldsAndProperties(Type type, BindingFlags bindingFlags) diff --git a/test/ZCS.DataContractResolver.Tests/DataContractResolverTests.cs b/test/ZCS.DataContractResolver.Tests/DataContractResolverTests.cs index 0c5f229..74d4512 100644 --- a/test/ZCS.DataContractResolver.Tests/DataContractResolverTests.cs +++ b/test/ZCS.DataContractResolver.Tests/DataContractResolverTests.cs @@ -20,15 +20,10 @@ public class Person public int Age; } - public class PersonWithoutDefaultConstructor + public class PersonWithoutDefaultConstructor(string fullName, int age) { - public PersonWithoutDefaultConstructor(string fullName, int age) - { - FullName = fullName; - Age = age; - } - public string FullName { get; } - public int Age { get; } + public string FullName { get; } = fullName; + public int Age { get; } = age; } public class PersonWithNonPublicMember @@ -272,15 +267,10 @@ public class Generic } [DataContract] - public class GenericWithConstructor + public class GenericWithConstructor(T value) { - public GenericWithConstructor(T value) - { - Value = value; - } - [DataMember] - public T Value { get; private set; } + public T Value { get; private set; } = value; } public class DataContractResolverTests @@ -303,23 +293,23 @@ private static System.Collections.IEnumerable TestCases() yield return new TestCaseData(ignoreCondition, (byte)1); yield return new TestCaseData(ignoreCondition, (sbyte)-1); - yield return new TestCaseData(ignoreCondition, Int16.MinValue); - yield return new TestCaseData(ignoreCondition, Int16.MaxValue); + yield return new TestCaseData(ignoreCondition, short.MinValue); + yield return new TestCaseData(ignoreCondition, short.MaxValue); - yield return new TestCaseData(ignoreCondition, Int32.MinValue); - yield return new TestCaseData(ignoreCondition, Int32.MaxValue); + yield return new TestCaseData(ignoreCondition, int.MinValue); + yield return new TestCaseData(ignoreCondition, int.MaxValue); - yield return new TestCaseData(ignoreCondition, Int64.MinValue); + yield return new TestCaseData(ignoreCondition, long.MinValue); yield return new TestCaseData(ignoreCondition, Int64.MaxValue); - yield return new TestCaseData(ignoreCondition, UInt16.MinValue); - yield return new TestCaseData(ignoreCondition, UInt16.MaxValue); + yield return new TestCaseData(ignoreCondition, ushort.MinValue); + yield return new TestCaseData(ignoreCondition, ushort.MaxValue); - yield return new TestCaseData(ignoreCondition, UInt32.MinValue); - yield return new TestCaseData(ignoreCondition, UInt32.MaxValue); + yield return new TestCaseData(ignoreCondition, uint.MinValue); + yield return new TestCaseData(ignoreCondition, uint.MaxValue); - yield return new TestCaseData(ignoreCondition, UInt64.MinValue); - yield return new TestCaseData(ignoreCondition, UInt64.MaxValue); + yield return new TestCaseData(ignoreCondition, ulong.MinValue); + yield return new TestCaseData(ignoreCondition, ulong.MaxValue); yield return new TestCaseData(ignoreCondition, 1.2m); @@ -341,20 +331,20 @@ private static System.Collections.IEnumerable TestCases() yield return new TestCaseData(ignoreCondition, new KeyValuePair("1", "2")); yield return new TestCaseData(ignoreCondition, new List()); - yield return new TestCaseData(ignoreCondition, new List { 0, 1, 2, 3 }); - yield return new TestCaseData(ignoreCondition, new List { "0", "1", "2", "3" }); + yield return new TestCaseData(ignoreCondition, (List)[0, 1, 2, 3]); + yield return new TestCaseData(ignoreCondition, (List)["0", "1", "2", "3"]); - yield return new TestCaseData(ignoreCondition, new int[0]); - yield return new TestCaseData(ignoreCondition, new int[] { 0, 1, 2, 3 }); - yield return new TestCaseData(ignoreCondition, new string[] { "0", "1", "2", "3" }); + yield return new TestCaseData(ignoreCondition, Array.Empty()); + yield return new TestCaseData(ignoreCondition, (int[])[0, 1, 2, 3]); + yield return new TestCaseData(ignoreCondition, (string[])["0", "1", "2", "3"]); yield return new TestCaseData(ignoreCondition, new Dictionary { { 1, 2 }, { 3, 4 } }); yield return new TestCaseData(ignoreCondition, new Dictionary { { 1, "2" }, { 3, "4" } }); yield return new TestCaseData(ignoreCondition, new Dictionary { { "1", "2" }, { "3", "4" } }); yield return new TestCaseData(ignoreCondition, new HashSet()); - yield return new TestCaseData(ignoreCondition, new HashSet { 0, 1, 2, 3 }); - yield return new TestCaseData(ignoreCondition, new HashSet { "0", "1", "2", "3" }); + yield return new TestCaseData(ignoreCondition, (HashSet)[0, 1, 2, 3]); + yield return new TestCaseData(ignoreCondition, (HashSet)["0", "1", "2", "3"]); yield return new TestCaseData(ignoreCondition, new Generic{ Value = 1 }); yield return new TestCaseData(ignoreCondition, new Generic { Value = "1" }); @@ -427,22 +417,22 @@ private static System.Collections.IEnumerable TestCases() yield return new TestCaseData(ignoreCondition, new PersonWithList() { FullName = "John Doe" }); yield return new TestCaseData(ignoreCondition, new PersonWithList() { Age = 21 }); yield return new TestCaseData(ignoreCondition, new PersonWithList() { FullName = "John Doe", Age = 21 }); - yield return new TestCaseData(ignoreCondition, new PersonWithList() { FullName = "John Doe", Age = 21, Friends = new List { new Person() { FullName = "John Doe", Age = 21 } } }); - yield return new TestCaseData(ignoreCondition, new PersonWithList() { FullName = "John Doe", Age = 21, List = new List { 0, 1, 2, 3, 4 } }); + yield return new TestCaseData(ignoreCondition, new PersonWithList() { FullName = "John Doe", Age = 21, Friends = [new() { FullName = "John Doe", Age = 21 }] }); + yield return new TestCaseData(ignoreCondition, new PersonWithList() { FullName = "John Doe", Age = 21, List = [0, 1, 2, 3, 4] }); yield return new TestCaseData(ignoreCondition, new PersonWithSet()); yield return new TestCaseData(ignoreCondition, new PersonWithSet() { FullName = "John Doe" }); yield return new TestCaseData(ignoreCondition, new PersonWithSet() { Age = 21 }); yield return new TestCaseData(ignoreCondition, new PersonWithSet() { FullName = "John Doe", Age = 21 }); - yield return new TestCaseData(ignoreCondition, new PersonWithSet() { FullName = "John Doe", Age = 21, Friends = new HashSet { new Person() { FullName = "John Doe", Age = 21 }, new Person() { FullName = "James Doe", Age = 22 } } }); - yield return new TestCaseData(ignoreCondition, new PersonWithSet() { FullName = "John Doe", Age = 21, Set = new HashSet { 0, 1, 2, 3, 4 } }); + yield return new TestCaseData(ignoreCondition, new PersonWithSet() { FullName = "John Doe", Age = 21, Friends = [new() { FullName = "John Doe", Age = 21 }, new() { FullName = "James Doe", Age = 22 }] }); + yield return new TestCaseData(ignoreCondition, new PersonWithSet() { FullName = "John Doe", Age = 21, Set = [0, 1, 2, 3, 4] }); yield return new TestCaseData(ignoreCondition, new PersonWithArray()); yield return new TestCaseData(ignoreCondition, new PersonWithArray() { FullName = "John Doe" }); yield return new TestCaseData(ignoreCondition, new PersonWithArray() { Age = 21 }); yield return new TestCaseData(ignoreCondition, new PersonWithArray() { FullName = "John Doe", Age = 21 }); - yield return new TestCaseData(ignoreCondition, new PersonWithArray() { FullName = "John Doe", Age = 21, Friends = new Person[] { new Person() { FullName = "John Doe", Age = 21 }, new Person() { FullName = "James Doe", Age = 22 } } }); - yield return new TestCaseData(ignoreCondition, new PersonWithArray() { FullName = "John Doe", Age = 21, Array = new int[] { 0, 1, 2, 3, 4 } }); + yield return new TestCaseData(ignoreCondition, new PersonWithArray() { FullName = "John Doe", Age = 21, Friends = [new() { FullName = "John Doe", Age = 21 }, new() { FullName = "James Doe", Age = 22 }] }); + yield return new TestCaseData(ignoreCondition, new PersonWithArray() { FullName = "John Doe", Age = 21, Array = [0, 1, 2, 3, 4] }); yield return new TestCaseData(ignoreCondition, new PersonContractWithIgnore()); yield return new TestCaseData(ignoreCondition, new PersonContractWithIgnore() { FullName = "John Doe" });