Open
Description
Originally discussed in #8651 (comment).
using Microsoft.AspNetCore.Components;
namespace Test;
[CascadingTypeParameter(nameof(TRow))]
public class Parent<TRow>: ComponentBase
{
[Parameter]
public RenderFragment<TRow>? ChildContent { get; set; }
}
public class Child<TRow> : ComponentBase
{
[Parameter]
public RenderFragment<TRow>? ChildContent { get; set; }
}
<Parent TRow="string?">
<Child Context="childContext">@childContext.Length</Child>
</Parent>
Apart from there being warnings (tracked in #7398):
warning CS8669: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source.
and in design-time builds even errors (see #8692),
there is a missing warning CS8602: Dereference of a possibly null reference.
.
It was originally suggested by @jsakamoto in #7428 (comment) to use default(Action<T>)
instead of default(T)
in code generation to support nullable reference types for T
- seems like it could work (need to think about type constraints - are errors reported correctly if the cascading type parameter has type constraints which are not met?).