我创建了一个基于 WinForms 的 UserControl 的工作组件。我已经覆盖了几个生成警告 CS8765 的现有属性。
CS8765: Nullability of type of parameter 'value' doesn't match overridden member (possibly because of nullability attributes).
此代码将警告设置为“set”。
/// <summary>
/// Gets or sets the font of the text
/// </summary>
[Browsable(true)]
public override Font Font
{
get => base.Font;
set
{
base.Font = value;
AdjustSize();
}
}
如果我将属性的类型从“字体”更改为“字体”? “set”的警告消失了,但“get”时我收到了不同的警告。
CS8764: Nullability of return type doesn't match overridden member (possibly because of nullability attributes).
这对我来说很有意义,因为我要重写的原始声明使用不可为 null 的 Font 版本。
在不忽略它的情况下,如何修复原来的警告?