question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add Results.Empty

See original GitHub issue

Background and Motivation

Sometimes you want to return a result that does not mutate the response in anyway. This happens when you have multiple branches in a route handle and one of them should be a noop. You are forced to return an IResult and we don’t have a built in result type that fills this role. Mvc has EmptyResult for this purpose.

Proposed API

namespace Microsoft.AspNetCore.Http
{
    public static class Results
    {
        public static IResult Empty(); // This could also be a property
    }
}

Usage Examples

app.MapGet("/{id}", (HttpContext context, string id) =>
{
    var httpProcessor = GetTargetStream(id);
    if (httpProcessor is null) return Results.NotFound();
 
    await httpProcessor.ProcessAsync(context);
     // Don't change what the httpProcessor did
    return Results.Empty();
});

Alternative Designs

Force people to write their own.

Risks

None

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
pranavkmcommented, Feb 28, 2022

API review:

We’ll use properties instead. Here’s the approved API:

public static class Results
{
+   public static IResult Empty { get; } = new EmptyResult();
}

public class ControllerBase
{
+    public static EmptyResult Empty { get; } = new ();
}
0reactions
davidfowlcommented, Mar 3, 2022

Yep

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add empty row to query results if no results found
The obvious way to achieve this is create a temp table, put the results into it, test for any rows in the temp...
Read more >
Setting Empty Results Messages
Specifies the action or actions to display for the empty results in either a dropdown menu, a link, or a button, depending on...
Read more >
how to display a 0 result instead an empty result
Solved: hi I use the search below and I would like to have a 0 results displayed when there is no events corresponding...
Read more >
Creating empty (avoid creating an output at all) when ...
Context: When using an if-condition inside an array_foreach() function, for each element with empty output ( result_when_false ), a '' or NULL ......
Read more >
Solved: Handling Empty Results
Solved: Hi I have a query which returns a list of issues in jason format which I then transform into a table and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found