-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Add sample project about native AOT (#68)
- Loading branch information
1 parent
a221c5e
commit 8df856a
Showing
5 changed files
with
62 additions
and
4 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,7 @@ | ||
namespace SimpleResults.Example.NativeAOT; | ||
|
||
[JsonSourceGenerationOptions( | ||
WriteIndented = true, | ||
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] | ||
[JsonSerializable(typeof(ListedResult<User>))] | ||
public partial class CustomContext : JsonSerializerContext { } |
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,6 @@ | ||
global using SimpleResults; | ||
global using SimpleResults.Example; | ||
global using SimpleResults.Example.NativeAOT; | ||
global using System.Globalization; | ||
global using System.Text.Json; | ||
global using System.Text.Json.Serialization; |
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,27 @@ | ||
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en"); | ||
var users = new List<User> | ||
{ | ||
new() { Id = "1", Name = "Bob" }, | ||
new() { Id = "2", Name = "Alice" } | ||
}; | ||
var userService = new UserService(users); | ||
ListedResult<User> result = userService.GetAll(); | ||
|
||
var json = JsonSerializer.Serialize( | ||
result, | ||
CustomContext.Default.ListedResultUser); | ||
|
||
Console.WriteLine(json); | ||
|
||
var deserializedResult = JsonSerializer.Deserialize( | ||
json, | ||
CustomContext.Default.ListedResultUser); | ||
|
||
Console.WriteLine(); | ||
Console.WriteLine("Status: " + deserializedResult.Status); | ||
foreach(var user in deserializedResult.Data) | ||
{ | ||
Console.WriteLine($"Id: {user.Id}, Name: {user.Name}"); | ||
} | ||
|
||
Console.ReadLine(); |
12 changes: 12 additions & 0 deletions
12
samples/SimpleResults.Example.NativeAOT/SimpleResults.Example.NativeAOT.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<PublishAot>true</PublishAot> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\SimpleResults.Example\SimpleResults.Example.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |