All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.plugins.csharp.S6800.html Maven / Gradle / Ivy

There is a newer version: 10.2.0.105762
Show newest version

Why is this an issue?

In Blazor, when a route parameter constraint is applied, the value is automatically cast to the corresponding component parameter type. If the constraint type does not match the component parameter type, it can lead to confusion and potential runtime errors due to unsuccessful casting. Therefore, it is crucial to ensure that the types of route parameters and component parameters match to prevent such issues and maintain code clarity.

How to fix it

Ensure the component parameter type matches the route parameter constraint type.

Constraint Type .NET Type

bool

bool

datetime

DateTime

decimal

decimal

double

double

float

float

guid

Guid

int

int

long

long

string

string

Code examples

Noncompliant code example

@page "/my-route/{Param:datetime}"

@code {
    [Parameter]
    public string Param { get; set; } // Noncompliant
}

Compliant solution

@page "/my-route/{Param:datetime}"

@code {
    [Parameter]
    public DateTime Param { get; set; } // Compliant
}

Resources

Documentation





© 2015 - 2024 Weber Informatics LLC | Privacy Policy