Merge pull request #215 from dotnet/r8

R8
pull/216/head
Rick Anderson 2023-10-09 15:04:09 -10:00 committed by GitHub
commit 4a827f3991
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,52 @@
#define RDG008 //RDG008F
#if NEVER
#elif RDG008
// <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.Id));
app.Run();
public class TodoRequest
{
public DateTime DueDate { get; }
public int Id { get; private set; }
public string Task { get; private set; }
// Additional constructors
public TodoRequest(int Id, string Task, DateTime DueDate)
{
this.Id = Id;
this.Task = Task;
this.DueDate = DueDate;
}
public TodoRequest(int Id, string Task)
: this(Id, Task, default)
{
}
}
[JsonSerializable(typeof(TodoRequest[]))]
internal partial class AppJsonSerializerContext : JsonSerializerContext
{
}
// </snippet_1>
#elif RDG008F
// <snippet_1f>
// </snippet_1f>
#endif

View File

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
<PublishAot>true</PublishAot>
<LangVersion>preview</LangVersion>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}