Skip to content

Set default parameter value if provided in RDG #47321

@captainsafia

Description

@captainsafia

Give the code:

string HandleRequest(string name = "Safia") => $"Hello {name}!";
app.MapGet("/hello", HandleRequest);

We emit the following code:

var name_raw = name_RouteOrQueryResolver(httpContext);
var name_temp = name_raw.Count > 0 ? (string?)name_raw : null;
string name_local = name_temp!;

When we should be emitting:

var name_raw = name_RouteOrQueryResolver(httpContext);
var name_temp = name_raw.Count > 0 ? (string?)name_raw : "Safia";
string name_local = name_temp!;

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcbugThis issue describes a behavior which is not expected - a bug.feature-rdgold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions