Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions aspnetcore/blazor/components/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1071,14 +1071,14 @@ For more information, see <xref:mvc/views/razor>.
> [!WARNING]
> Providing initial values for component parameters is supported, but don't create a component that writes to its own parameters after the component is rendered for the first time. For more information, see <xref:blazor/components/overwriting-parameters>.

Component parameters should be declared as *auto-properties*, meaning that they shouldn't contain custom logic in their `get` or `set` accessors. For example, the following `StartData` property is an auto-property:
Component parameters should be declared as [automatically-implemented properties (*auto properties*)](/dotnet/csharp/programming-guide/classes-and-structs/auto-implemented-properties), meaning that they shouldn't contain custom logic in their `get` or `set` accessors. For example, the following `StartData` property is an auto property:

```csharp
[Parameter]
public DateTime StartData { get; set; }
```

Don't place custom logic in the `get` or `set` accessor because component parameters are purely intended for use as a channel for a parent component to flow information to a child component. If a `set` accessor of a child component property contains logic that causes rerendering of the parent component, an infinite rendering loop results.
Don't place custom logic in the `get` or `set` accessor because component parameters are purely intended for use as a channel for a parent component to flow information to a child component. If a `set` accessor of a child component property contains logic that causes rerendering of the parent component, an infinite rendering loop results. Other side effects include unexpected extra renderings and parameter value overwrites.

To transform a received parameter value:

Expand Down
2 changes: 1 addition & 1 deletion aspnetcore/diagnostics/bl0001.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "BL0001: Component parameter should have public setters"
description: "Learn about analysis rule BL0001: Component parameter should have public setters"
author: pranavkm
author: guardrex
monikerRange: '>= aspnetcore-3.1'
ms.author: riande
ms.date: 10/21/2021
Expand Down
2 changes: 1 addition & 1 deletion aspnetcore/diagnostics/bl0002.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "BL0002: Component has multiple CaptureUnmatchedValues parameters"
description: "Learn about analysis rule BL0002: Component has multiple CaptureUnmatchedValues parameters"
author: pranavkm
author: guardrex
monikerRange: '>= aspnetcore-3.1'
ms.author: riande
ms.date: 10/21/2021
Expand Down
2 changes: 1 addition & 1 deletion aspnetcore/diagnostics/bl0003.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "BL0003: Component parameter with CaptureUnmatchedValues has the wrong type"
description: "Learn about analysis rule BL0003: Component parameter with CaptureUnmatchedValues has the wrong type"
author: pranavkm
author: guardrex
monikerRange: '>= aspnetcore-3.1'
ms.author: riande
ms.date: 10/21/2021
Expand Down
2 changes: 1 addition & 1 deletion aspnetcore/diagnostics/bl0004.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "BL0004: Component parameter should be public"
description: "Learn about analysis rule BL0004: Component parameter should be public"
author: pranavkm
author: guardrex
monikerRange: '>= aspnetcore-3.1'
ms.author: riande
ms.date: 10/21/2021
Expand Down
2 changes: 1 addition & 1 deletion aspnetcore/diagnostics/bl0005.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "BL0005: Component parameter should not be set outside of its component"
description: "Learn about analysis rule BL0005: Component parameter should not be set outside of its component"
author: pranavkm
author: guardrex
monikerRange: '>= aspnetcore-3.1'
ms.author: riande
ms.date: 10/21/2021
Expand Down
2 changes: 1 addition & 1 deletion aspnetcore/diagnostics/bl0006.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "BL0006: Do not use RenderTree types"
description: "Learn about analysis rule BL0006: Do not use RenderTree types"
author: pranavkm
author: guardrex
monikerRange: '>= aspnetcore-3.1'
ms.author: riande
ms.date: 10/21/2021
Expand Down
34 changes: 34 additions & 0 deletions aspnetcore/diagnostics/bl0007.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: "BL0007: Component parameter '{0}' should be auto property"
description: "Learn about analysis rule BL0007: Component parameter '{0}' should be auto property"
author: guardrex
monikerRange: '>= aspnetcore-3.1'
ms.author: riande
ms.date: 04/07/2025
uid: diagnostics/bl0007
---
# BL0007: Component parameter '{0}' should be auto property

| | Value |
| - | - |
| **Rule ID** | BL0007 |
| **Category** | Usage |
| **Fix is breaking or non-breaking** | Non-breaking |

## Cause

A [component parameter](xref:blazor/components/index#component-parameters), which is a public [C# property](/dotnet/csharp/programming-guide/classes-and-structs/properties) of a component class with the [`[Parameter]` attribute](xref:Microsoft.AspNetCore.Components.ParameterAttribute), isn't an [automatically-implemented property (*auto property*)](/dotnet/csharp/programming-guide/classes-and-structs/auto-implemented-properties).

## 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](/dotnet/csharp/programming-guide/classes-and-structs/using-properties), 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](xref:blazor/components/lifecycle#after-parameters-are-set-onparameterssetasync).

## When to suppress warnings

Do not suppress a warning from this rule.
1 change: 1 addition & 0 deletions aspnetcore/diagnostics/code-analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Diagnostic ID:
* [BL0004](xref:diagnostics/bl0004)
* [BL0005](xref:diagnostics/bl0005)
* [BL0006](xref:diagnostics/bl0006)
* [BL0007](xref:diagnostics/bl0007)
* [MVC1000](xref:diagnostics/mvc1000)
* [MVC1001](xref:diagnostics/mvc1001)
* [MVC1002](xref:diagnostics/mvc1002)
Expand Down
2 changes: 2 additions & 0 deletions aspnetcore/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,8 @@ items:
uid: diagnostics/bl0005
- name: BL0006
uid: diagnostics/bl0006
- name: BL0007
uid: diagnostics/bl0007
- name: MVC1000
uid: diagnostics/mvc1000
- name: MVC1001
Expand Down