Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x
- name: Restore
run: dotnet restore
- name: Build
Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x
- name: Create Release NuGet package
run: |
arrTag=(${GITHUB_REF//\// })
Expand Down
55 changes: 1 addition & 54 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -35,65 +35,12 @@
<RepositoryUrl>https://github.com/synercoder/Primitives/</RepositoryUrl>
<RestoreSources>
https://api.nuget.org/v3/index.json;
https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json;
</RestoreSources>
<UseSharedCompilation>true</UseSharedCompilation>
</PropertyGroup>

<PropertyGroup>
<LangVersion>10.0</LangVersion>
<LangVersion>12.0</LangVersion>
</PropertyGroup>


<!-- Define target framework specific constants.
https://apisof.net/
+===================+=======+==========+=====================+=============+=================+====================+==============+=========+============|===============|
| SUPPORTS | MATHF | HASHCODE | EXTENDED_INTRINSICS | SPAN_STREAM | ENCODING_STRING | RUNTIME_INTRINSICS | CODECOVERAGE | HOTPATH | CREATESPAN | BITOPERATIONS |
+===================+=======+==========+=====================+=============+=================+====================+==============+=========|============|===============|
| >=netcoreapp3.1 | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y |
| netstandard2.1 | Y | Y | N | Y | Y | N | Y | N | Y | N |
| netstandard2.0 | N | N | N | N | N | N | Y | N | N | N |
| net48 | N | N | Y | N | N | N | Y | N | N | N |
+===================+=======+==========+=====================+=============+=================+====================+==============+=========|============|===============|
-->
<Choose>
<When Condition="'$(TargetFramework)' == 'net48'">
<PropertyGroup>
<DefineConstants>$(DefineConstants);SUPPORTS_EXTENDED_INTRINSICS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_CODECOVERAGE</DefineConstants>
</PropertyGroup>
</When>
<When Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PropertyGroup>
<DefineConstants>$(DefineConstants);SUPPORTS_EXTENDED_INTRINSICS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_CODECOVERAGE</DefineConstants>
</PropertyGroup>
</When>
<When Condition="'$(TargetFramework)' == 'netstandard2.1'">
<PropertyGroup>
<DefineConstants>$(DefineConstants);SUPPORTS_MATHF</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_HASHCODE</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_SPAN_STREAM</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_ENCODING_STRING</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_CODECOVERAGE</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_CREATESPAN</DefineConstants>
</PropertyGroup>
</When>
<When Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)','netcoreapp3.1'))">
<!--NETCORE 3.1. NET5.0, and future versions will fallback to this as the closest target.-->
<PropertyGroup>
<DefineConstants>$(DefineConstants);SUPPORTS_MATHF</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_HASHCODE</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_EXTENDED_INTRINSICS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_SPAN_STREAM</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_ENCODING_STRING</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_RUNTIME_INTRINSICS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_CODECOVERAGE</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_HOTPATH</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_CREATESPAN</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_BITOPERATIONS</DefineConstants>
</PropertyGroup>
</When>
</Choose>

</Project>
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>

<PropertyGroup>
<TargetFrameworks>net48;netcoreapp3.1;netstandard1.6;netstandard2.0;netstandard2.1;net5.0;net6.0</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileDirectory)..\Directory.Build.props</MSBuildAllProjects>
<SynercodingProjectCategory>src</SynercodingProjectCategory>
</PropertyGroup>
Expand Down
57 changes: 57 additions & 0 deletions src/Synercoding.Primitives/JsonConverters/PointJsonConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Synercoding.Primitives.JsonConverters;

public class PointJsonConverter : JsonConverter<Point>
{
public static PointJsonConverter Instance { get; } = new();

public override Point Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.String)
{
var textValue = reader.GetString() ?? throw new JsonException();

if (Point.TryParse(textValue, out var value))
return value;

throw new JsonException();
}

if (reader.TokenType != JsonTokenType.StartObject)
throw new JsonException();

var complexPoint = default(Point);
while (reader.Read())
{
if (reader.TokenType == JsonTokenType.EndObject)
return complexPoint;

if (reader.TokenType == JsonTokenType.PropertyName)
{
string propertyName = reader.GetString() ?? throw new JsonException();
reader.Read();
switch (propertyName)
{
case nameof(Point.X):
Value width = ValueJsonConverter.Instance.Read(ref reader, typeof(Value), options);
complexPoint = complexPoint with { X = width };
break;
case nameof(Point.Y):
Value height = ValueJsonConverter.Instance.Read(ref reader, typeof(Value), options);
complexPoint = complexPoint with { Y = height };
break;
}
}
}

throw new JsonException();
}

public override void Write(Utf8JsonWriter writer, Point value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Synercoding.Primitives.JsonConverters;

public class RectangleJsonConverter : JsonConverter<Rectangle>
{
public static RectangleJsonConverter Instance { get; } = new();

public override Rectangle Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.String)
{
var textValue = reader.GetString() ?? throw new JsonException();

if (Rectangle.TryParse(textValue, out var value))
return value;

throw new JsonException();
}

if (reader.TokenType != JsonTokenType.StartObject)
throw new JsonException();

var complexRectangle = default(Rectangle);
while (reader.Read())
{
if (reader.TokenType == JsonTokenType.EndObject)
return complexRectangle;

if (reader.TokenType == JsonTokenType.PropertyName)
{
string propertyName = reader.GetString() ?? throw new JsonException();
reader.Read();
switch (propertyName)
{
case nameof(Rectangle.LLX):
Value llx = ValueJsonConverter.Instance.Read(ref reader, typeof(Value), options);
complexRectangle = complexRectangle with { LLX = llx };
break;
case nameof(Rectangle.LLY):
Value lly = ValueJsonConverter.Instance.Read(ref reader, typeof(Value), options);
complexRectangle = complexRectangle with { LLY = lly };
break;
case nameof(Rectangle.URX):
Value urx = ValueJsonConverter.Instance.Read(ref reader, typeof(Value), options);
complexRectangle = complexRectangle with { URX = urx };
break;
case nameof(Rectangle.URY):
Value ury = ValueJsonConverter.Instance.Read(ref reader, typeof(Value), options);
complexRectangle = complexRectangle with { URY = ury };
break;
}
}
}

throw new JsonException();
}

public override void Write(Utf8JsonWriter writer, Rectangle value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString());
}
}
57 changes: 57 additions & 0 deletions src/Synercoding.Primitives/JsonConverters/SizeJsonConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Synercoding.Primitives.JsonConverters;

public class SizeJsonConverter : JsonConverter<Size>
{
public static SizeJsonConverter Instance { get; } = new();

public override Size Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.String)
{
var textValue = reader.GetString() ?? throw new JsonException();

if (Size.TryParse(textValue, out var value))
return value;

throw new JsonException();
}

if (reader.TokenType != JsonTokenType.StartObject)
throw new JsonException();

var complexSize = default(Size);
while (reader.Read())
{
if (reader.TokenType == JsonTokenType.EndObject)
return complexSize;

if (reader.TokenType == JsonTokenType.PropertyName)
{
string propertyName = reader.GetString() ?? throw new JsonException();
reader.Read();
switch (propertyName)
{
case nameof(Size.Width):
Value width = ValueJsonConverter.Instance.Read(ref reader, typeof(Value), options);
complexSize = complexSize with { Width = width };
break;
case nameof(Size.Height):
Value height = ValueJsonConverter.Instance.Read(ref reader, typeof(Value), options);
complexSize = complexSize with { Height = height };
break;
}
}
}

throw new JsonException();
}

public override void Write(Utf8JsonWriter writer, Size value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString());
}
}
65 changes: 65 additions & 0 deletions src/Synercoding.Primitives/JsonConverters/SpacingJsonConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Synercoding.Primitives.JsonConverters;

public class SpacingJsonConverter : JsonConverter<Spacing>
{
public static SpacingJsonConverter Instance { get; } = new();

public override Spacing Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.String)
{
var textValue = reader.GetString() ?? throw new JsonException();

if (Spacing.TryParse(textValue, out var value))
return value;

throw new JsonException();
}

if (reader.TokenType != JsonTokenType.StartObject)
throw new JsonException();

var complexSpacing = default(Spacing);
while (reader.Read())
{
if (reader.TokenType == JsonTokenType.EndObject)
return complexSpacing;

if (reader.TokenType == JsonTokenType.PropertyName)
{
string propertyName = reader.GetString() ?? throw new JsonException();
reader.Read();
switch (propertyName)
{
case nameof(Spacing.Left):
Value left = ValueJsonConverter.Instance.Read(ref reader, typeof(Value), options);
complexSpacing = complexSpacing with { Left = left };
break;
case nameof(Spacing.Right):
Value right = ValueJsonConverter.Instance.Read(ref reader, typeof(Value), options);
complexSpacing = complexSpacing with { Right = right };
break;
case nameof(Spacing.Top):
Value top = ValueJsonConverter.Instance.Read(ref reader, typeof(Value), options);
complexSpacing = complexSpacing with { Top = top };
break;
case nameof(Spacing.Bottom):
Value bottom = ValueJsonConverter.Instance.Read(ref reader, typeof(Value), options);
complexSpacing = complexSpacing with { Bottom = bottom };
break;
}
}
}

throw new JsonException();
}

public override void Write(Utf8JsonWriter writer, Spacing value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString());
}
}
29 changes: 29 additions & 0 deletions src/Synercoding.Primitives/JsonConverters/UnitJsonConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Synercoding.Primitives.JsonConverters;

public class UnitJsonConverter : JsonConverter<Unit>
{
public static UnitJsonConverter Instance { get; } = new();

public override Unit Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.String)
throw new JsonException();

var textValue = reader.GetString() ?? throw new JsonException();

if (Unit.TryParse(textValue, out var unit))
return unit;

throw new JsonException();
}

public override void Write(Utf8JsonWriter writer, Unit value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString());
}
}

Loading