Blazor Component - How can I implement custom compile-time parameter validation?

175 views Asked by At

@MrC aka Shaun Curtis detailed the @bind-Value syntactic sugar for components here.

As some may know, you may specify @bind-Value or @ValueChanged, but not both. If you specify both, your code won't build and you'll get a RZ10010 error.

RZ10010: The component parameter ‘ValueChanged’ is used two or more times for this component. Parameters must be unique (case-insensitive). The component parameter ‘ValueChanged’ is generated by the ‘@bind-Value’ directive attribute.


So I cite RZ10010 as an example of Blazor component compile-time parameter validation, implemented natively by .NET Core.

My question is:

How can I implement my own Blazor component compile-time parameter validation?

For instance, if MyComponent.razor looked like this:

[Parameter]
public string ParameterA { get; set; }

[Parameter]
public string ParameterB { get; set; }

And I wanted to allow a value for ParameterA or ParameterB, but not both, how would I do that?

0

There are 0 answers