Rdg004 update /8

pull/30509/head
Rick Anderson 2023-09-27 16:04:18 -10:00
parent 869e92f42c
commit a1af54a2a8
1 changed files with 2 additions and 15 deletions

View File

@ -22,26 +22,13 @@ This diagnostic is emitted by the Request Delegate Generator when an endpoint co
The Request Delegate Generator runs at compile-time and needs to be able to statically analyze route handlers in an application. Anonymous types are generated with an unspeakable type name and are not statically analyzable. The following endpoint will produce the diagnostic. The Request Delegate Generator runs at compile-time and needs to be able to statically analyze route handlers in an application. Anonymous types are generated with an unspeakable type name and are not statically analyzable. The following endpoint will produce the diagnostic.
```razor :::code language="csharp" source="~/../AspNetCore.Docs.Samples/fundamentals/aot/diagnostics/Rdg4/Program.cs" id="snippet_1" highlight="13":::
var app = WebApplication.Create();
app.MapGet("/v1/todos", () => new { Id = 1, Task = "Write tests" });
app.Run();
```
## How to fix violations ## How to fix violations
Declare the route handler with a concrete type as the return type. Declare the route handler with a concrete type as the return type.
```razor
var app = WebApplication.Create();
app.MapGet("/v1/todos", () => new Todo(1, "Write tests"); :::code language="csharp" source="~/../AspNetCore.Docs.Samples/fundamentals/aot/diagnostics/Rdg4/Program.cs" id="snippet_1f" highlight="13":::
app.Run();
record Todo(int Id, string Task);
```
## When to suppress warnings ## When to suppress warnings