add RDG012 example
parent
854b582aee
commit
3caa5d1ec8
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue