From 9616c2a189fab6ffc2c0ddeba18d614c62b7f96c Mon Sep 17 00:00:00 2001 From: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com> Date: Sat, 30 Sep 2023 21:08:42 +0200 Subject: [PATCH] add code examples for rdg011 --- fundamentals/aot/diagnostics/Rdg11/Program.cs | 57 +++++++++++++++++++ .../aot/diagnostics/Rdg11/Rdg11.csproj | 11 ++++ 2 files changed, 68 insertions(+) create mode 100644 fundamentals/aot/diagnostics/Rdg11/Program.cs create mode 100644 fundamentals/aot/diagnostics/Rdg11/Rdg11.csproj diff --git a/fundamentals/aot/diagnostics/Rdg11/Program.cs b/fundamentals/aot/diagnostics/Rdg11/Program.cs new file mode 100644 index 0000000..aaad063 --- /dev/null +++ b/fundamentals/aot/diagnostics/Rdg11/Program.cs @@ -0,0 +1,57 @@ +#define RDG11F // RDG11 RDG11F +#if NEVER +#elif RDG11 +// +var builder = WebApplication.CreateSlimBuilder(args); + +var app = builder.Build(); +app.MapEndpoints(); +app.Run(); + +public static class RouteBuilderExtensions +{ + public static IEndpointRouteBuilder MapEndpoints(this IEndpointRouteBuilder app) where T : class, new() + { + app.MapPost("/input", (T value) => value); + app.MapGet("/result", () => new T()); + app.MapPost("/input-with-wrapper", (Wrapper value) => value); + app.MapGet("/async", async () => + { + await Task.CompletedTask; + return new T(); + }); + return app; + } +} + +record Todo(); +record Wrapper { } +// +#elif RDG11F +// +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 value) => value); + app.MapGet("/async", async () => + { + await Task.CompletedTask; + return new Todo(); + }); + return app; + } +} + +record Todo(); +record Wrapper { } +// +#endif diff --git a/fundamentals/aot/diagnostics/Rdg11/Rdg11.csproj b/fundamentals/aot/diagnostics/Rdg11/Rdg11.csproj new file mode 100644 index 0000000..c12d03b --- /dev/null +++ b/fundamentals/aot/diagnostics/Rdg11/Rdg11.csproj @@ -0,0 +1,11 @@ + + + + net8.0 + enable + enable + true + preview + + + \ No newline at end of file