-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Updated to NET9 and added trimming/NativeAOT support.
- Loading branch information
Showing
32 changed files
with
226 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Console.WriteLine("Build, rebuild or publish this app to see trimming warnings."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
|
||
<PublishTrimmed>true</PublishTrimmed> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\libs\H.Formatters.System.Text.Json\H.Formatters.System.Text.Json.csproj" /> | ||
<ProjectReference Include="..\..\libs\H.Formatters\H.Formatters.csproj" /> | ||
<ProjectReference Include="..\..\libs\H.Pipes.AccessControl\H.Pipes.AccessControl.csproj" /> | ||
<ProjectReference Include="..\..\libs\H.Pipes\H.Pipes.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<TrimmerRootAssembly Include="H.Formatters" /> | ||
<TrimmerRootAssembly Include="H.Formatters.System.Text.Json" /> | ||
<TrimmerRootAssembly Include="H.Pipes" /> | ||
<TrimmerRootAssembly Include="H.Pipes.AccessControl" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup Label="Publish"> | ||
<RuntimeIdentifier Condition="$([MSBuild]::IsOSPlatform('windows'))">win-x64</RuntimeIdentifier> | ||
<RuntimeIdentifier Condition="!$([MSBuild]::IsOSPlatform('windows'))">osx-arm64</RuntimeIdentifier> | ||
|
||
<SelfContained>true</SelfContained> | ||
</PropertyGroup> | ||
|
||
<Target Name="ProduceTrimmingWarnings" AfterTargets="Build"> | ||
<CallTarget Targets="Publish"/> | ||
</Target> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/libs/H.Formatters.BinaryFormatter/H.Formatters.BinaryFormatter.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/libs/H.Formatters.MessagePack/H.Formatters.MessagePack.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/libs/H.Formatters.Newtonsoft.Json/H.Formatters.Newtonsoft.Json.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/libs/H.Formatters.System.Text.Json/SystemTextJsonNativeAotFormatter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace H.Formatters; | ||
|
||
/// <summary> | ||
/// A formatter that uses <see cref="JsonSerializer"/> inside for serialization/deserialization | ||
/// </summary> | ||
public class SystemTextJsonNativeAotFormatter(JsonSerializerContext context) : FormatterBase | ||
{ | ||
/// <summary> | ||
/// Default: UTF8. | ||
/// </summary> | ||
public Encoding Encoding { get; set; } = Encoding.UTF8; | ||
|
||
/// <summary> | ||
/// Set this to enable trimming/NativeAOT support. | ||
/// </summary> | ||
public JsonSerializerContext Context { get; set; } = context; | ||
|
||
protected override byte[] SerializeInternal(object? obj) | ||
{ | ||
if (obj == null) | ||
{ | ||
return []; | ||
} | ||
|
||
var json = JsonSerializer.Serialize(obj, obj.GetType(), Context); | ||
var bytes = Encoding.GetBytes(json); | ||
|
||
return bytes; | ||
} | ||
|
||
protected override T DeserializeInternal<T>(byte[] bytes) | ||
{ | ||
var json = Encoding.GetString(bytes); | ||
var obj = (T?)JsonSerializer.Deserialize(json, typeof(T), Context); | ||
|
||
return obj ?? throw new InvalidOperationException("obj is null."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.