aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Codebehind - BL9993 : Component parameters should not be public.

Open vertonghenb opened this issue 8 years ago • 2 comments

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!

vertonghenb avatar Jun 04 '18 00:06 vertonghenb

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

zefubachs avatar Jun 04 '18 06:06 zefubachs

@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.

SteveSandersonMS avatar Jun 04 '18 09:06 SteveSandersonMS