Aspnetcore: Codebehind - BL9993 : Component parameters should not be public.

Created on 4 Jun 2018  路  2Comments  路  Source: dotnet/aspnetcore

Just wondering if it's a flaw in the analyzer or it's on purpose. While following the docs to get a
code behind experience. The analyzer is throwing the warning to make the parameters of the component Private, however if we want to use the parameters in the .cshtml they have to be public.

MyButton.cshtml

@inherits MyButton
<button>
    @Text
</button>

MyButton.cs

    public class MyButton : BlazorComponent
    {
        [Parameter] public string Text { get; set; }
    }

Then again, which road are we heading towards, more Code Behind exp. or rather mixing both via Functions, which is preferred?

Thx!

area-blazor

Most helpful comment

A workaround i use is to make the property protected instead of public.

All 2 comments

A workaround i use is to make the property protected instead of public.

@zefubachs is correct - use protected.

But it's not really a "workaround", it's the expected and standard way to share otherwise private state with a derived class.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

markrendle picture markrendle  路  3Comments

BrennanConroy picture BrennanConroy  路  3Comments

rbanks54 picture rbanks54  路  3Comments

Kevenvz picture Kevenvz  路  3Comments

farhadibehnam picture farhadibehnam  路  3Comments