Skip to content

Commit 9ab3703

Browse files
committed
Update to only use .NET 8 and add support for System.Text.Json serialization
1 parent 3617606 commit 9ab3703

26 files changed

+595
-679
lines changed

Diff for: .github/workflows/dotnet-core.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Setup .NET Core
3434
uses: actions/setup-dotnet@v1
3535
with:
36-
dotnet-version: 6.0.x
36+
dotnet-version: 8.0.x
3737
- name: Restore
3838
run: dotnet restore
3939
- name: Build
@@ -73,7 +73,7 @@ jobs:
7373
- name: Setup .NET Core
7474
uses: actions/setup-dotnet@v1
7575
with:
76-
dotnet-version: 6.0.x
76+
dotnet-version: 8.0.x
7777
- name: Create Release NuGet package
7878
run: |
7979
arrTag=(${GITHUB_REF//\// })

Diff for: Directory.Build.props

+1-54
Original file line numberDiff line numberDiff line change
@@ -35,65 +35,12 @@
3535
<RepositoryUrl>https://github.com/synercoder/Primitives/</RepositoryUrl>
3636
<RestoreSources>
3737
https://api.nuget.org/v3/index.json;
38-
https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json;
3938
</RestoreSources>
4039
<UseSharedCompilation>true</UseSharedCompilation>
4140
</PropertyGroup>
4241

4342
<PropertyGroup>
44-
<LangVersion>10.0</LangVersion>
43+
<LangVersion>12.0</LangVersion>
4544
</PropertyGroup>
4645

47-
48-
<!-- Define target framework specific constants.
49-
https://apisof.net/
50-
+===================+=======+==========+=====================+=============+=================+====================+==============+=========+============|===============|
51-
| SUPPORTS | MATHF | HASHCODE | EXTENDED_INTRINSICS | SPAN_STREAM | ENCODING_STRING | RUNTIME_INTRINSICS | CODECOVERAGE | HOTPATH | CREATESPAN | BITOPERATIONS |
52-
+===================+=======+==========+=====================+=============+=================+====================+==============+=========|============|===============|
53-
| >=netcoreapp3.1 | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y |
54-
| netstandard2.1 | Y | Y | N | Y | Y | N | Y | N | Y | N |
55-
| netstandard2.0 | N | N | N | N | N | N | Y | N | N | N |
56-
| net48 | N | N | Y | N | N | N | Y | N | N | N |
57-
+===================+=======+==========+=====================+=============+=================+====================+==============+=========|============|===============|
58-
-->
59-
<Choose>
60-
<When Condition="'$(TargetFramework)' == 'net48'">
61-
<PropertyGroup>
62-
<DefineConstants>$(DefineConstants);SUPPORTS_EXTENDED_INTRINSICS</DefineConstants>
63-
<DefineConstants>$(DefineConstants);SUPPORTS_CODECOVERAGE</DefineConstants>
64-
</PropertyGroup>
65-
</When>
66-
<When Condition="'$(TargetFramework)' == 'netstandard2.0'">
67-
<PropertyGroup>
68-
<DefineConstants>$(DefineConstants);SUPPORTS_EXTENDED_INTRINSICS</DefineConstants>
69-
<DefineConstants>$(DefineConstants);SUPPORTS_CODECOVERAGE</DefineConstants>
70-
</PropertyGroup>
71-
</When>
72-
<When Condition="'$(TargetFramework)' == 'netstandard2.1'">
73-
<PropertyGroup>
74-
<DefineConstants>$(DefineConstants);SUPPORTS_MATHF</DefineConstants>
75-
<DefineConstants>$(DefineConstants);SUPPORTS_HASHCODE</DefineConstants>
76-
<DefineConstants>$(DefineConstants);SUPPORTS_SPAN_STREAM</DefineConstants>
77-
<DefineConstants>$(DefineConstants);SUPPORTS_ENCODING_STRING</DefineConstants>
78-
<DefineConstants>$(DefineConstants);SUPPORTS_CODECOVERAGE</DefineConstants>
79-
<DefineConstants>$(DefineConstants);SUPPORTS_CREATESPAN</DefineConstants>
80-
</PropertyGroup>
81-
</When>
82-
<When Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)','netcoreapp3.1'))">
83-
<!--NETCORE 3.1. NET5.0, and future versions will fallback to this as the closest target.-->
84-
<PropertyGroup>
85-
<DefineConstants>$(DefineConstants);SUPPORTS_MATHF</DefineConstants>
86-
<DefineConstants>$(DefineConstants);SUPPORTS_HASHCODE</DefineConstants>
87-
<DefineConstants>$(DefineConstants);SUPPORTS_EXTENDED_INTRINSICS</DefineConstants>
88-
<DefineConstants>$(DefineConstants);SUPPORTS_SPAN_STREAM</DefineConstants>
89-
<DefineConstants>$(DefineConstants);SUPPORTS_ENCODING_STRING</DefineConstants>
90-
<DefineConstants>$(DefineConstants);SUPPORTS_RUNTIME_INTRINSICS</DefineConstants>
91-
<DefineConstants>$(DefineConstants);SUPPORTS_CODECOVERAGE</DefineConstants>
92-
<DefineConstants>$(DefineConstants);SUPPORTS_HOTPATH</DefineConstants>
93-
<DefineConstants>$(DefineConstants);SUPPORTS_CREATESPAN</DefineConstants>
94-
<DefineConstants>$(DefineConstants);SUPPORTS_BITOPERATIONS</DefineConstants>
95-
</PropertyGroup>
96-
</When>
97-
</Choose>
98-
9946
</Project>

Diff for: src/Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33

44
<PropertyGroup>
5-
<TargetFrameworks>net48;netcoreapp3.1;netstandard1.6;netstandard2.0;netstandard2.1;net5.0;net6.0</TargetFrameworks>
5+
<TargetFramework>net8.0</TargetFramework>
66
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileDirectory)..\Directory.Build.props</MSBuildAllProjects>
77
<SynercodingProjectCategory>src</SynercodingProjectCategory>
88
</PropertyGroup>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Text.Json;
3+
using System.Text.Json.Serialization;
4+
5+
namespace Synercoding.Primitives.JsonConverters;
6+
7+
public class PointJsonConverter : JsonConverter<Point>
8+
{
9+
public static PointJsonConverter Instance { get; } = new();
10+
11+
public override Point Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
12+
{
13+
if (reader.TokenType == JsonTokenType.String)
14+
{
15+
var textValue = reader.GetString() ?? throw new JsonException();
16+
17+
if (Point.TryParse(textValue, out var value))
18+
return value;
19+
20+
throw new JsonException();
21+
}
22+
23+
if (reader.TokenType != JsonTokenType.StartObject)
24+
throw new JsonException();
25+
26+
var complexPoint = default(Point);
27+
while (reader.Read())
28+
{
29+
if (reader.TokenType == JsonTokenType.EndObject)
30+
return complexPoint;
31+
32+
if (reader.TokenType == JsonTokenType.PropertyName)
33+
{
34+
string propertyName = reader.GetString() ?? throw new JsonException();
35+
reader.Read();
36+
switch (propertyName)
37+
{
38+
case nameof(Point.X):
39+
Value width = ValueJsonConverter.Instance.Read(ref reader, typeof(Value), options);
40+
complexPoint = complexPoint with { X = width };
41+
break;
42+
case nameof(Point.Y):
43+
Value height = ValueJsonConverter.Instance.Read(ref reader, typeof(Value), options);
44+
complexPoint = complexPoint with { Y = height };
45+
break;
46+
}
47+
}
48+
}
49+
50+
throw new JsonException();
51+
}
52+
53+
public override void Write(Utf8JsonWriter writer, Point value, JsonSerializerOptions options)
54+
{
55+
writer.WriteStringValue(value.ToString());
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using System.Text.Json;
3+
using System.Text.Json.Serialization;
4+
5+
namespace Synercoding.Primitives.JsonConverters;
6+
7+
public class RectangleJsonConverter : JsonConverter<Rectangle>
8+
{
9+
public static RectangleJsonConverter Instance { get; } = new();
10+
11+
public override Rectangle Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
12+
{
13+
if (reader.TokenType == JsonTokenType.String)
14+
{
15+
var textValue = reader.GetString() ?? throw new JsonException();
16+
17+
if (Rectangle.TryParse(textValue, out var value))
18+
return value;
19+
20+
throw new JsonException();
21+
}
22+
23+
if (reader.TokenType != JsonTokenType.StartObject)
24+
throw new JsonException();
25+
26+
var complexRectangle = default(Rectangle);
27+
while (reader.Read())
28+
{
29+
if (reader.TokenType == JsonTokenType.EndObject)
30+
return complexRectangle;
31+
32+
if (reader.TokenType == JsonTokenType.PropertyName)
33+
{
34+
string propertyName = reader.GetString() ?? throw new JsonException();
35+
reader.Read();
36+
switch (propertyName)
37+
{
38+
case nameof(Rectangle.LLX):
39+
Value llx = ValueJsonConverter.Instance.Read(ref reader, typeof(Value), options);
40+
complexRectangle = complexRectangle with { LLX = llx };
41+
break;
42+
case nameof(Rectangle.LLY):
43+
Value lly = ValueJsonConverter.Instance.Read(ref reader, typeof(Value), options);
44+
complexRectangle = complexRectangle with { LLY = lly };
45+
break;
46+
case nameof(Rectangle.URX):
47+
Value urx = ValueJsonConverter.Instance.Read(ref reader, typeof(Value), options);
48+
complexRectangle = complexRectangle with { URX = urx };
49+
break;
50+
case nameof(Rectangle.URY):
51+
Value ury = ValueJsonConverter.Instance.Read(ref reader, typeof(Value), options);
52+
complexRectangle = complexRectangle with { URY = ury };
53+
break;
54+
}
55+
}
56+
}
57+
58+
throw new JsonException();
59+
}
60+
61+
public override void Write(Utf8JsonWriter writer, Rectangle value, JsonSerializerOptions options)
62+
{
63+
writer.WriteStringValue(value.ToString());
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Text.Json;
3+
using System.Text.Json.Serialization;
4+
5+
namespace Synercoding.Primitives.JsonConverters;
6+
7+
public class SizeJsonConverter : JsonConverter<Size>
8+
{
9+
public static SizeJsonConverter Instance { get; } = new();
10+
11+
public override Size Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
12+
{
13+
if (reader.TokenType == JsonTokenType.String)
14+
{
15+
var textValue = reader.GetString() ?? throw new JsonException();
16+
17+
if (Size.TryParse(textValue, out var value))
18+
return value;
19+
20+
throw new JsonException();
21+
}
22+
23+
if (reader.TokenType != JsonTokenType.StartObject)
24+
throw new JsonException();
25+
26+
var complexSize = default(Size);
27+
while (reader.Read())
28+
{
29+
if (reader.TokenType == JsonTokenType.EndObject)
30+
return complexSize;
31+
32+
if (reader.TokenType == JsonTokenType.PropertyName)
33+
{
34+
string propertyName = reader.GetString() ?? throw new JsonException();
35+
reader.Read();
36+
switch (propertyName)
37+
{
38+
case nameof(Size.Width):
39+
Value width = ValueJsonConverter.Instance.Read(ref reader, typeof(Value), options);
40+
complexSize = complexSize with { Width = width };
41+
break;
42+
case nameof(Size.Height):
43+
Value height = ValueJsonConverter.Instance.Read(ref reader, typeof(Value), options);
44+
complexSize = complexSize with { Height = height };
45+
break;
46+
}
47+
}
48+
}
49+
50+
throw new JsonException();
51+
}
52+
53+
public override void Write(Utf8JsonWriter writer, Size value, JsonSerializerOptions options)
54+
{
55+
writer.WriteStringValue(value.ToString());
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using System.Text.Json;
3+
using System.Text.Json.Serialization;
4+
5+
namespace Synercoding.Primitives.JsonConverters;
6+
7+
public class SpacingJsonConverter : JsonConverter<Spacing>
8+
{
9+
public static SpacingJsonConverter Instance { get; } = new();
10+
11+
public override Spacing Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
12+
{
13+
if (reader.TokenType == JsonTokenType.String)
14+
{
15+
var textValue = reader.GetString() ?? throw new JsonException();
16+
17+
if (Spacing.TryParse(textValue, out var value))
18+
return value;
19+
20+
throw new JsonException();
21+
}
22+
23+
if (reader.TokenType != JsonTokenType.StartObject)
24+
throw new JsonException();
25+
26+
var complexSpacing = default(Spacing);
27+
while (reader.Read())
28+
{
29+
if (reader.TokenType == JsonTokenType.EndObject)
30+
return complexSpacing;
31+
32+
if (reader.TokenType == JsonTokenType.PropertyName)
33+
{
34+
string propertyName = reader.GetString() ?? throw new JsonException();
35+
reader.Read();
36+
switch (propertyName)
37+
{
38+
case nameof(Spacing.Left):
39+
Value left = ValueJsonConverter.Instance.Read(ref reader, typeof(Value), options);
40+
complexSpacing = complexSpacing with { Left = left };
41+
break;
42+
case nameof(Spacing.Right):
43+
Value right = ValueJsonConverter.Instance.Read(ref reader, typeof(Value), options);
44+
complexSpacing = complexSpacing with { Right = right };
45+
break;
46+
case nameof(Spacing.Top):
47+
Value top = ValueJsonConverter.Instance.Read(ref reader, typeof(Value), options);
48+
complexSpacing = complexSpacing with { Top = top };
49+
break;
50+
case nameof(Spacing.Bottom):
51+
Value bottom = ValueJsonConverter.Instance.Read(ref reader, typeof(Value), options);
52+
complexSpacing = complexSpacing with { Bottom = bottom };
53+
break;
54+
}
55+
}
56+
}
57+
58+
throw new JsonException();
59+
}
60+
61+
public override void Write(Utf8JsonWriter writer, Spacing value, JsonSerializerOptions options)
62+
{
63+
writer.WriteStringValue(value.ToString());
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Text.Json;
3+
using System.Text.Json.Serialization;
4+
5+
namespace Synercoding.Primitives.JsonConverters;
6+
7+
public class UnitJsonConverter : JsonConverter<Unit>
8+
{
9+
public static UnitJsonConverter Instance { get; } = new();
10+
11+
public override Unit Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
12+
{
13+
if (reader.TokenType != JsonTokenType.String)
14+
throw new JsonException();
15+
16+
var textValue = reader.GetString() ?? throw new JsonException();
17+
18+
if (Unit.TryParse(textValue, out var unit))
19+
return unit;
20+
21+
throw new JsonException();
22+
}
23+
24+
public override void Write(Utf8JsonWriter writer, Unit value, JsonSerializerOptions options)
25+
{
26+
writer.WriteStringValue(value.ToString());
27+
}
28+
}
29+

0 commit comments

Comments
 (0)