dotnet / dotnet/aspnetcore

Investigate redesign of public types to unions

Open
#66,549 4 comments 4 reactions 0 assignees View on GitHub
area-minimal feature-request
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

One of the obvious types coming to mind is `TypedResults` https://github.com/dotnet/aspnetcore/blob/c31cb17a6dc348ba66a731902922ae5bc796d2a9/src/Http/Http.Results/src/TypedResults.cs#L25

We could possible change the `Results` to support unions, so that users may provide different return types in a single union type. See example below https://github.com/dotnet/aspnetcore/blob/c31cb17a6dc348ba66a731902922ae5bc796d2a9/src/Http/Http.Results/src/ResultsOfT.Generated.cs#L24-L26

```csharp
ResultUnion, NotFound, BadRequest> GetTodo(int id)
{
if (id < 0) return TypedResults.BadRequest("Invalid ID");
if (id == 0) return TypedResults.NotFound();
return TypedResults.Ok(new Todo(id, "Buy milk"));
}
```

This issue should open the discussion for any other type as well to be rewritten in union representation - not only `TypedResults`. This may come later than NET11, but should improve the user experience.

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.