Skip to content

Commit 0bb2f21

Browse files
committed
Add coverage for analyzer violation BL0007
1 parent 09f5757 commit 0bb2f21

File tree

9 files changed

+43
-6
lines changed

9 files changed

+43
-6
lines changed

aspnetcore/diagnostics/bl0001.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "BL0001: Component parameter should have public setters"
33
description: "Learn about analysis rule BL0001: Component parameter should have public setters"
4-
author: pranavkm
4+
author: guardrex
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.date: 10/21/2021

aspnetcore/diagnostics/bl0002.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "BL0002: Component has multiple CaptureUnmatchedValues parameters"
33
description: "Learn about analysis rule BL0002: Component has multiple CaptureUnmatchedValues parameters"
4-
author: pranavkm
4+
author: guardrex
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.date: 10/21/2021

aspnetcore/diagnostics/bl0003.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "BL0003: Component parameter with CaptureUnmatchedValues has the wrong type"
33
description: "Learn about analysis rule BL0003: Component parameter with CaptureUnmatchedValues has the wrong type"
4-
author: pranavkm
4+
author: guardrex
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.date: 10/21/2021

aspnetcore/diagnostics/bl0004.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "BL0004: Component parameter should be public"
33
description: "Learn about analysis rule BL0004: Component parameter should be public"
4-
author: pranavkm
4+
author: guardrex
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.date: 10/21/2021

aspnetcore/diagnostics/bl0005.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "BL0005: Component parameter should not be set outside of its component"
33
description: "Learn about analysis rule BL0005: Component parameter should not be set outside of its component"
4-
author: pranavkm
4+
author: guardrex
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.date: 10/21/2021

aspnetcore/diagnostics/bl0006.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "BL0006: Do not use RenderTree types"
33
description: "Learn about analysis rule BL0006: Do not use RenderTree types"
4-
author: pranavkm
4+
author: guardrex
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.date: 10/21/2021

aspnetcore/diagnostics/bl0007.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: "BL0007: Component parameter '{0}' should be auto property"
3+
description: "Learn about analysis rule BL0007: Component parameter '{0}' should be auto property"
4+
author: guardrex
5+
monikerRange: '>= aspnetcore-3.1'
6+
ms.author: riande
7+
ms.date: 04/07/2025
8+
uid: diagnostics/bl0007
9+
---
10+
# BL0007: Component parameter '{0}' should be auto property
11+
12+
| | Value |
13+
| - | - |
14+
| **Rule ID** | BL0007 |
15+
| **Category** | Usage |
16+
| **Fix is breaking or non-breaking** | Non-breaking |
17+
18+
## Cause
19+
20+
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).
21+
22+
## Rule description
23+
24+
A component parameter is a framework-managed communication channel between a parent and a child component. Developers shouldn't write to the parameter in a [set accessor/setter (`set`)](/dotnet/csharp/programming-guide/classes-and-structs/using-properties#the-set-accessor), either from inside or outside the component.
25+
26+
Side effects of writing directly to a component parameter in a setter include infinite rendering loops, unexpected extra renderings, and overwriting parameter changes.
27+
28+
## How to fix violations
29+
30+
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 modify the parameter's value. For more information, see the [`OnParametersSet{Async}` lifecycle method](xref:blazor/components/lifecycle#after-parameters-are-set-onparameterssetasync).
31+
32+
## When to suppress warnings
33+
34+
Do not suppress a warning from this rule.

aspnetcore/diagnostics/code-analysis.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Diagnostic ID:
4949
* [BL0004](xref:diagnostics/bl0004)
5050
* [BL0005](xref:diagnostics/bl0005)
5151
* [BL0006](xref:diagnostics/bl0006)
52+
* [BL0007](xref:diagnostics/bl0007)
5253
* [MVC1000](xref:diagnostics/mvc1000)
5354
* [MVC1001](xref:diagnostics/mvc1001)
5455
* [MVC1002](xref:diagnostics/mvc1002)

aspnetcore/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,8 @@ items:
14611461
uid: diagnostics/bl0005
14621462
- name: BL0006
14631463
uid: diagnostics/bl0006
1464+
- name: BL0007
1465+
uid: diagnostics/bl0007
14641466
- name: MVC1000
14651467
uid: diagnostics/mvc1000
14661468
- name: MVC1001

0 commit comments

Comments
 (0)