Description
the example:
MyComponent.razor
@inherits ITComponentBase
@typeparam T
MyComponent.razor.cs
[CascadingTypeParameter(nameof(T))]
public partial class MyComponent<T> : ComponentBase
{
[Parameter]
public MyQueryCommand<T> QueryCommand { get; set; } = default!;
}
public class MyQueryCommand<T>
{
}
Page.razor
<MyComponent QueryCommand="new MyQueryCommand<AuthUser>()">
</MyComponent>
thats works perfect, but when I put a restriction in paramtype T, fails
MyComponent.razor.cs
[CascadingTypeParameter(nameof(T))]
public partial class MyComponent<T> : ComponentBase where T : IDomain
{
[Parameter]
public MyQueryCommand<T> QueryCommand { get; set; } = default!;
}
public class MyQueryCommand<T> where T : IDomain
{
}
The sourceGenerator: error CS0314: El tipo 'T' no se puede usar como parámetro de tipo 'T' en el tipo o método genérico 'MyQueryCommand<T>'. No hay conversión boxing ni conversión de parámetro de tipo de 'T' a 'ITProject.Domain.IDomain'.
Page.razor.g.cs
public static void CreateMyComponent_0<T>(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, int __seq0, global::ITProject.Components.MyQueryCommand<T> __arg0)
where T : global::ITProject.Domain.IDomain
{
....................
}
public static void CreateMyComponent_0_CaptureParameters<T>(global::ITProject.Components.MyQueryCommand<T> __arg0, out global::ITProject.Components.MyQueryCommand<T> __arg0_out)
{
__arg0_out = __arg0;
}
if I put a restriction in CreateMyComponent_0_CaptureParameters<T>
same as it is in CreateMyComponent_0<T>
all works
public static void CreateMyComponent_0_CaptureParameters<T>(global::ITProject.Components.MyQueryCommand<T> __arg0, out global::ITProject.Components.MyQueryCommand<T> __arg0_out)
where T : global::ITProject.Domain.IDomain
{
__arg0_out = __arg0;
}
Activity