Description
openedon Sep 30, 2023
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.