代码检查:对具有非空类型种类的类型参数的基类型约束的冗余可空注解
此检查会在类型约束上报告可空注解,当其他约束如 class、 struct、 unmanaged 或 notnull 已经使类型参数为非空时。 在这种情况下,约束上的 ? 是矛盾的,没有任何作用。
#nullable enable
using System;
class C
{
void M<T>() where T : notnull, IDisposable?
{
}
}
#nullable enable
using System;
class C
{
void M<T>() where T : notnull, IDisposable
{
}
}
根据约束列表,也可以通过另一种快速修复移除冗余的非空类型种类约束。
2026年 5月 8日