add code examples for rdg011

pull/202/head
Tim Deschryver 2023-09-30 21:08:42 +02:00
parent da04803e4a
commit 9616c2a189
No known key found for this signature in database
GPG Key ID: 36E0C712874EB36B
2 changed files with 68 additions and 0 deletions

View File

@ -0,0 +1,57 @@
#define RDG11F // RDG11 RDG11F
#if NEVER
#elif RDG11
// <snippet_1>
var builder = WebApplication.CreateSlimBuilder(args);
var app = builder.Build();
app.MapEndpoints<Todo>();
app.Run();
public static class RouteBuilderExtensions
{
public static IEndpointRouteBuilder MapEndpoints<T>(this IEndpointRouteBuilder app) where T : class, new()
{
app.MapPost("/input", (T value) => value);
app.MapGet("/result", () => new T());
app.MapPost("/input-with-wrapper", (Wrapper<T> value) => value);
app.MapGet("/async", async () =>
{
await Task.CompletedTask;
return new T();
});
return app;
}
}
record Todo();
record Wrapper<T> { }
// </snippet_1>
#elif RDG11F
// <snippet_1f>
var builder = WebApplication.CreateSlimBuilder(args);
var app = builder.Build();
app.MapTodoEndpoints();
app.Run();
public static class TodoRouteBuilderExtensions
{
public static IEndpointRouteBuilder MapTodoEndpoints(this IEndpointRouteBuilder app)
{
app.MapPost("/input", (Todo value) => value);
app.MapGet("/result", () => new Todo());
app.MapPost("/input-with-wrapper", (Wrapper<Todo> value) => value);
app.MapGet("/async", async () =>
{
await Task.CompletedTask;
return new Todo();
});
return app;
}
}
record Todo();
record Wrapper<T> { }
// </snippet_1f>
#endif

View File

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