Back to Aspnetcore

BL0007: Component parameter '{0}' should be auto property

aspnetcore/diagnostics/bl0007.md

latest1.8 KB
Original Source

BL0007: Component parameter '{0}' should be auto property

Value
Rule IDBL0007
CategoryUsage
Fix is breaking or non-breakingNon-breaking

Cause

A component parameter, which is a public C# property of a component class with the [Parameter] attribute, isn't an automatically-implemented property (auto property).

Rule description

A component parameter is a framework-managed communication channel between a parent and a child component. Developers shouldn't read or write to the parameter in a get (getter) or set (setter) accessor, either from inside or outside the component.

Possible side effects of interacting directly with a component parameter include infinite rendering loops, unexpected extra renderings, and parameter value overwrites.

How to fix violations

Implement the component parameter as an auto property and override xref:Microsoft.AspNetCore.Components.ComponentBase.OnParametersSet%2A or xref:Microsoft.AspNetCore.Components.ComponentBase.OnParametersSetAsync%2A in the component class to read or transform the parameter's value. For more information, see the OnParametersSet{Async} lifecycle method.

When to suppress warnings

Do not suppress a warning from this rule.