add RDG012 example

pull/30579/head
Tim Deschryver 2023-10-04 19:44:33 +02:00
parent 854b582aee
commit 3caa5d1ec8
No known key found for this signature in database
GPG Key ID: 36E0C712874EB36B
1 changed files with 4 additions and 18 deletions

View File

@ -20,32 +20,18 @@ This diagnostic is emitted by the Request Delegate Generator when an endpoint co
### Rule description
The Request Delegate Generator only supports
Endpoints that use an inaccessible type (`private` or `protected`) are not supported.
The endpoints within `MapEndpoints` produce this diagnostic because of the `Todo` type has the `private` accessibility modifiers.
```csharp
var app = WebApplication.Create();
:::code language="csharp" source="~/../AspNetCore.Docs.Samples/fundamentals/aot/diagnostics/Rdg12/Program.cs" id="snippet_1" highlight="9-20, 22":::
app.MapPost("/vl/todos", (Todo todo)
=> Results.Created(todo));
app.Run();
private record Todo(int Id, string Task);
```
## How to fix violations
When applicable, set the target parameter type with a friendly accessibility.
```csharp
var app = WebApplication.Create();
app.MapPost("/vl/todos", (Todo todo)
=> Results.Created(todo));
:::code language="csharp" source="~/../AspNetCore.Docs.Samples/fundamentals/aot/diagnostics/Rdg12/Program.cs" id="snippet_1f" highlight="9-20, 22":::
app.Run();
public record Todo(int Id, string Task);
```
## When to suppress warnings