Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pfo-omicsstudio opened this issue Oct 22, 2024 · 0 comments · Fixed by #1366
Closed

Comments

@pfo-omicsstudio
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants