Rdg004 update /8
parent
869e92f42c
commit
a1af54a2a8
|
@ -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.
|
||||
|
||||
```razor
|
||||
var app = WebApplication.Create();
|
||||
|
||||
app.MapGet("/v1/todos", () => new { Id = 1, Task = "Write tests" });
|
||||
|
||||
app.Run();
|
||||
```
|
||||
:::code language="csharp" source="~/../AspNetCore.Docs.Samples/fundamentals/aot/diagnostics/Rdg4/Program.cs" id="snippet_1" highlight="13":::
|
||||
|
||||
## How to fix violations
|
||||
|
||||
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");
|
||||
|
||||
app.Run();
|
||||
|
||||
record Todo(int Id, string Task);
|
||||
```
|
||||
:::code language="csharp" source="~/../AspNetCore.Docs.Samples/fundamentals/aot/diagnostics/Rdg4/Program.cs" id="snippet_1f" highlight="13":::
|
||||
|
||||
## When to suppress warnings
|
||||
|
||||
|
|
Loading…
Reference in New Issue