Skip to content

Formalize coding style guideline for attribute placement #51043

Open

Description

Historically, I believe we’ve put attributes above the attributed member, like this:

[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
    return ...
}

But I’m seeing more frequent use of putting single attributes on the same line as the attributed member, like this example from the Blazor Web App project template:

[CascadingParameter] public HttpContext? HttpContext { get; set; }

While I understand the appeal of the conciseness of this approach, I think it’s problematic because the line of code can get very long if you need to specify attribute parameters and properties, or if you need to add additional attributes. We could say the single line pattern is ok, but only when there's a single attribute with no parameters, but I don't think we've ever done that with controllers or data annotations. My personal preference is to stick with the historical convention of putting the attribute above the member.

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

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions