不支持绑定可为 null 的类型

Bind nullable types unsupported

我指的是Blazor issue 1007.

我需要实现 可空类型绑定 才能在数据库中使用它们。

我的示例适用于所有不可为 null 的类型,但如果我在我的 class 中定义一个可为 null 的类型,我会收到错误消息:

Error: System.ArgumentException: 'bind' does not accept values of type System.Nullable (.........) To read and write this value type, wrap it in a property of type string with suitable getters and setters.

如何实现这样的包装器?

那就是这样的:

private bool realValue;

public string MyNullable
{
    get
    {
        return (string)realValue; //your logic for nulls here
    }
    set
    {
        realValue == bool.Parse(value); //your logic for nulls here
    }
}