Merge pull request #207 from timdeschryver/rdg012-example-code

add RDG012 example
pull/210/head
Rick Anderson 2023-10-04 09:15:26 -10:00 committed by GitHub
commit e6df7765ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,59 @@
#define RDG12F // RDG12 RDG12F
#if NEVER
#elif RDG12
// <snippet_1>
var builder = WebApplication.CreateSlimBuilder(args);
var app = builder.Build();
app.MapEndpoints();
app.Run();
public static class TodoRouteBuilderExtensions
{
public static IEndpointRouteBuilder MapEndpoints(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;
}
private record Todo { };
}
record Wrapper<T> { }
// </snippet_1>
#elif RDG12F
// <snippet_1f>
var builder = WebApplication.CreateSlimBuilder(args);
var app = builder.Build();
app.MapEndpoints();
app.Run();
public static class TodoRouteBuilderExtensions
{
public static IEndpointRouteBuilder MapEndpoints(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;
}
public 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>