Merge pull request #214 from timdeschryver/rdg010-example-code

add RDG010 example
pull/215/head
Rick Anderson 2023-10-09 08:24:31 -10:00 committed by GitHub
commit d5ab200072
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,36 @@
#define RDG10F // RDG10 RDG10F
#if NEVER
#elif RDG10
// <snippet_1>
using Microsoft.AspNetCore.Mvc;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/todos/{id}", ([AsParameters] TodoRequest? request)
=> Results.Ok(new Todo(request!.Id)));
app.Run();
public record TodoRequest(HttpContext HttpContext, [FromRoute] int Id);
public record Todo(int Id);
// </snippet_1>
#elif RDG10F
// <snippet_1f>
using Microsoft.AspNetCore.Mvc;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/todos/{id}", ([AsParameters] TodoRequest request)
=> Results.Ok(new Todo(request.Id)));
app.Run();
public record TodoRequest(HttpContext HttpContext, [FromRoute] int Id);
public record Todo(int Id);
// </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>
<InvariantGlobalization>true</InvariantGlobalization>
<EnableRequestDelegateGenerator>true</EnableRequestDelegateGenerator>
</PropertyGroup>
</Project>