I-edit

Ibahagi sa


ASP0006: Do not use non-literal sequence numbers

Value
Rule ID ASP0006
Category Usage
Fix is breaking or non-breaking Non-breaking

Cause

An invocation on a method in RenderTreeBuilder containing a sequence number that isn't a literal as a parameter.

Rule description

Blazor's UI diffing algorithm relies on sequence numbers to determine which elements have changed. Computing the sequence number dynamically or using a counter can result in poor diffing performance. Instead, use a literal sequence number that maps to the source code line for the element. For example, the following code produces an error:

using Microsoft.AspNetCore.Components.Rendering;
var builder = new RenderTreeBuilder();
var seqNum = 1;
builder.OpenElement(seqNum, "div");
builder.CloseElement();

How to fix violations

To fix a violation of this rule, make sure that calls to methods on the RenderTreeBuilder class that take a sequence number as a parameter use a literal sequence number.

using Microsoft.AspNetCore.Components.Rendering;
var builder = new RenderTreeBuilder();
builder.OpenElement(0, "div");
builder.CloseElement();

When to suppress warnings

Do not suppress a warning from this rule. Using a non-literal sequence number can result in performance degradation.