Skip to content

Inconsistent Formatting for new() Operator Compared to Explicit Object Constructors #1364

@pfo-omicsstudio

Description

@pfo-omicsstudio

Input:

ProblemDetails problemDetails = new()
{
    Status = StatusCodes.Status500InternalServerError,
    Title = "An unexpected error occurred. Please try again later.",
    Detail = environment.IsDevelopment() ? exception.Message : null,
    Instance = context.Request.Path,
};

Output:

ProblemDetails problemDetails =
    new()
    {
        Status = StatusCodes.Status500InternalServerError,
        Title = "An unexpected error occurred. Please try again later.",
        Detail = environment.IsDevelopment() ? exception.Message : null,
        Instance = context.Request.Path,
    };

Expected behavior:

Currently, when using the new() operator, the formatting applies differently than when using the explicit object constructor. The explicit constructor formats like this:

ProblemDetails problemDetails = new ProblemDetails
{
    Status = StatusCodes.Status500InternalServerError,
    Title = "An unexpected error occurred. Please try again later.",
    Detail = environment.IsDevelopment() ? exception.Message : null,
    Instance = context.Request.Path,
};

It would be more consistent to apply the same formatting to the new() operator, like this:

ProblemDetails problemDetails = new()
{
    Status = StatusCodes.Status500InternalServerError,
    Title = "An unexpected error occurred. Please try again later.",
    Detail = environment.IsDevelopment() ? exception.Message : null,
    Instance = context.Request.Path,
};

The current behavior appears to contradict the formatting used for explicit object constructors.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions