我基于WinForm的userControl创建了一个工作组件.我已经覆盖了生成警告CS 8765的几个现有属性.
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();
}
}
如果我将属性的类型从"Font"更改为"Font?""set"的警告会消失,但我在"get"上得到了不同的警告.
CS8764: Nullability of return type doesn't match overridden member (possibly because of nullability attributes).
这对我来说是有意义的,因为我正在重写的原始声明使用了Font的不可空版本.
在不忽略它的情况下,如何修复我原来的警告?