AspNetCore.Docs.Samples/fundamentals/aot/diagnostics/Rdg7/Program.cs

74 lines
1.5 KiB
C#

#define RDG11F // RDG11 RDG11F
#if NEVER
#elif RDG11
// <snippet_1>
using System.Text.Json.Serialization;
var builder = WebApplication.CreateSlimBuilder(args);
builder.Services.ConfigureHttpJsonOptions(options =>
{
options.SerializerOptions.TypeInfoResolverChain.Insert(0,
AppJsonSerializerContext.Default);
});
var app = builder.Build();
app.MapPut("/v1/todos/{id}", ([AsParameters] TodoRequest request)
=> Results.Ok(request.Todo));
app.Run();
public class TodoRequest
{
public int Id { get; set; }
public Todo Todo { get; set; }
private TodoRequest()
{
}
}
public record Todo(int Id, string Task);
[JsonSerializable(typeof(Todo[]))]
internal partial class AppJsonSerializerContext : JsonSerializerContext
{
}
// </snippet_1>
#elif RDG11F
// <snippet_1f>
using System.Text.Json.Serialization;
var builder = WebApplication.CreateSlimBuilder(args);
builder.Services.ConfigureHttpJsonOptions(options =>
{
options.SerializerOptions.TypeInfoResolverChain.Insert(0,
AppJsonSerializerContext.Default);
});
var app = builder.Build();
app.MapPut("/v1/todos/{id}", ([AsParameters] TodoRequest request)
=> Results.Ok(request.Todo));
app.Run();
public class TodoRequest(int Id, Todo todo)
{
public int Id { get; set; } = Id;
public Todo Todo { get; set; } = todo;
}
public record Todo(int Id, string Task);
[JsonSerializable(typeof(Todo[]))]
internal partial class AppJsonSerializerContext : JsonSerializerContext
{
}
// </snippet_1f>
#endif