dotnet / dotnet/aspnetcore

[Codefixer] Recommend using `TypedResults` over using `Results`

Open
#45,217 3 comments 0 reactions 0 assignees View on GitHub
analyzer api-suggestion area-minimal
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

## Background and Motivation

- Recommend returning `TypedResults` instead of `Results`
- Recommend adding the `Results<>` return type to your class

```csharp
app.MapGet("/", (int id) => SomeCondition(id) ? Results.Ok() : Results.NotFound());
```

Becomes

```csharp
app.MapGet("/", (int id) => SomeCondition(id) ? TypedResults.Ok() : TypedResults.NotFound());
```

And further becomes:

```csharp
app.MapGet("/", Results(int id) => SomeCondition(id) ? TypedResults.Ok() : TypedResults.NotFound());
```

## Proposed Analyzer

### Analyzer Behavior and Message

### Category

- [ ] Design
- [ ] Documentation
- [ ] Globalization
- [ ] Interoperability
- [ ] Maintainability
- [ ] Naming
- [ ] Performance
- [ ] Reliability
- [ ] Security
- [ ] Style
- [ ] Usage

### Severity Level

- [ ] Error
- [X] Warning
- [ ] Info
- [ ] Hidden

## Usage Scenarios

## Risks

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.