如何在blazor(.razor页面)中设置默认类型@typeparam TValue = bool

时间:2020-02-03 05:22:18

标签: blazor blazor-server-side

我们在Checkbox组件的checked属性中提供了TValue支持。如何在blazor(.razor页面)中设置默认类型@typeparam TValue = bool

@using Microsoft.AspNetCore.Components.Web;
@using Microsoft.AspNetCore.Components.Rendering
@inherits BaseComponent;
@implements ICheckBox;
@typeparam TValue = bool;

1 个答案:

答案 0 :(得分:1)

这是一个已知问题 https://github.com/dotnet/aspnetcore/issues/13619

但是我在项目中所做的解决方法

public class DateTimePickerComponent : DateTimePickerComponent<DateTime?> { } // default Type value

public class DateTimePickerComponent<T> : BaseSubComponent { .... } // all business here

,并且在组件I中,其中一个来自

@inherits DateTimePickerComponent  // default type will be DateTime?
@inherits DateTimePickerComponent<DateTime> // this also work