Skip to content

Commit

Permalink
Add ASP.NET example
Browse files Browse the repository at this point in the history
  • Loading branch information
cston committed Mar 1, 2021
1 parent 1592d42 commit 5b8fc1a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions proposals/csharp-10.0/lambda-improvements.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,30 @@ Allowing explicit return types would also provide control over compiler performa
A natural type for lambda expressions and method groups will allow more scenarios where lambdas and method groups may be used without an explicit delegate type, including as initializers in `var` declarations.
Requiring explicit delegate types for lambdas and method groups has been a friction point for customers, and has become an impediment to progress in ASP.NET with recent work on [MapAction](https://github.com/dotnet/aspnetcore/pull/29878).

[ASP.NET MapAction](https://github.com/dotnet/aspnetcore/pull/29878) today where `MapAction()` takes a `System.Delegate action` argument:
```csharp
[HttpGet("/")] Todo GetTodo() => new(Id: 0, Name: "Name");
app.MapAction((Func<Todo>)GetTodo);

[HttpPost("/")] Todo PostTodo([FromBody] Todo todo) => todo);
app.MapAction((Func<Todo, Todo>)PostTodo);
```

[ASP.NET MapAction](https://github.com/dotnet/aspnetcore/pull/29878) with natural types for method groups:
```csharp
[HttpGet("/")] Todo GetTodo() => new(Id: 0, Name: "Name");
app.MapAction(GetTodo);

[HttpPost("/")] Todo PostTodo([FromBody] Todo todo) => todo);
app.MapAction(PostTodo);
```

[ASP.NET MapAction](https://github.com/dotnet/aspnetcore/pull/29878) with attributes and natural types for lambda expressions:
```csharp
app.MapAction([HttpGet("/")] () => new Todo(Id: 0, Name: "Name"));
app.MapAction([HttpPost("/")] ([FromBody] Todo todo) => todo);
```

## Attributes
Attributes may be added to lambda expressions.
```csharp
Expand Down

0 comments on commit 5b8fc1a

Please sign in to comment.