add code examples for rdg011
parent
da04803e4a
commit
9616c2a189
|
@ -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
|
|
@ -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>
|
Loading…
Reference in New Issue