【问题标题】:How to set default type @typeparam TValue = bool in blazor(.razor page)如何在 blazor(.razor 页面)中设置默认类型 @typeparam TValue = bool
【发布时间】:2020-02-03 05:22:18
【问题描述】:

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

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

【问题讨论】:

  • 答案真的很好。你应该接受它。

标签: blazor blazor-server-side


【解决方案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

【讨论】:

    猜你喜欢
    • 2014-03-18
    • 2014-12-06
    • 2010-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-23
    • 2021-03-01
    • 2018-08-28
    相关资源
    最近更新 更多