Skip to content

Commit

Permalink
Merge pull request #43 from zcsizmadia/migrate-to-net8
Browse files Browse the repository at this point in the history
Add .NET 8.0 support
  • Loading branch information
zcsizmadia authored Nov 19, 2023
2 parents f2a3a14 + 53b395c commit d4dd88c
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:
branches: [ main ]
release:
types: [ published ]
types: [ published ]

jobs:
build:
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<Project>
<PropertyGroup Label="Frameworks">
<ClassLibTargetFrameworks>netstandard2.0;net7.0</ClassLibTargetFrameworks>
<TestTargetFrameworks>net6.0;net7.0</TestTargetFrameworks>
<SampleTargetFramework>net7.0</SampleTargetFramework>
<ClassLibTargetFrameworks>net7.0;net8.0</ClassLibTargetFrameworks>
<TestTargetFrameworks>net7.0;net8.0</TestTargetFrameworks>
<SampleTargetFramework>net8.0</SampleTargetFramework>

<!-- Unit tests are running against EOL SDKs as well. Disable all warnings related to EOL SDK -->
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>

<!-- Suppress warnings related to preview SDKs -->
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>

<LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup Label="Versions">
Expand Down
4 changes: 0 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@

<!-- Run "dotnet list package (dash,dash)outdated" to see the latest versions of each package.-->

<ItemGroup Label="Package Dependencies">
<PackageVersion Include="System.Text.Json" Version="8.0.0" Condition="'$(TargetFramework)' != 'netcoreapp3.1' OR '$(TargetFramework)'== 'net5.0' OR '$(TargetFramework)' != 'net6.0'"/>
</ItemGroup>

<ItemGroup Label="Build Dependencies">
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
8 changes: 1 addition & 7 deletions src/ZCS.DataContractResolver/DataContractResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MemberInfo> EnumerateFieldsAndProperties(Type type, BindingFlags bindingFlags)
Expand Down
68 changes: 29 additions & 39 deletions test/ZCS.DataContractResolver.Tests/DataContractResolverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -272,15 +267,10 @@ public class Generic<T>
}

[DataContract]
public class GenericWithConstructor<T>
public class GenericWithConstructor<T>(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
Expand All @@ -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);

Expand All @@ -341,20 +331,20 @@ private static System.Collections.IEnumerable TestCases()
yield return new TestCaseData(ignoreCondition, new KeyValuePair<string, string>("1", "2"));

yield return new TestCaseData(ignoreCondition, new List<int>());
yield return new TestCaseData(ignoreCondition, new List<int> { 0, 1, 2, 3 });
yield return new TestCaseData(ignoreCondition, new List<string> { "0", "1", "2", "3" });
yield return new TestCaseData(ignoreCondition, (List<int>)[0, 1, 2, 3]);
yield return new TestCaseData(ignoreCondition, (List<string>)["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<int>());
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<int, int> { { 1, 2 }, { 3, 4 } });
yield return new TestCaseData(ignoreCondition, new Dictionary<int, string> { { 1, "2" }, { 3, "4" } });
yield return new TestCaseData(ignoreCondition, new Dictionary<string, string> { { "1", "2" }, { "3", "4" } });

yield return new TestCaseData(ignoreCondition, new HashSet<int>());
yield return new TestCaseData(ignoreCondition, new HashSet<int> { 0, 1, 2, 3 });
yield return new TestCaseData(ignoreCondition, new HashSet<string> { "0", "1", "2", "3" });
yield return new TestCaseData(ignoreCondition, (HashSet<int>)[0, 1, 2, 3]);
yield return new TestCaseData(ignoreCondition, (HashSet<string>)["0", "1", "2", "3"]);

yield return new TestCaseData(ignoreCondition, new Generic<int>{ Value = 1 });
yield return new TestCaseData(ignoreCondition, new Generic<string> { Value = "1" });
Expand Down Expand Up @@ -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<Person> { new Person() { FullName = "John Doe", Age = 21 } } });
yield return new TestCaseData(ignoreCondition, new PersonWithList() { FullName = "John Doe", Age = 21, List = new List<int> { 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<Person> { 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<int> { 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" });
Expand Down

0 comments on commit d4dd88c

Please sign in to comment.