代码检查:容器为 null 性特性用法与非容器类型的声明
此检查会报告将容器项 为 null 性注解应用于没有可为 null 项的类型。
典型示例是在值类型或其他非容器声明上使用 [ItemNotNull]或 [ItemCanBeNull]。 在这些情况下,注解不会影响代码分析,只会增加干扰。
示例
在此示例中, [ItemNotNull] 注解应用于 int 属性。 由于 int 是值类型且不能为 null,该注解是冗余的。
using JetBrains.Annotations;
public class Example
{
[ItemNotNull]
public int RetryCount => 3;
}
using JetBrains.Annotations;
public class Example
{
public int RetryCount => 3;
}
快速修复
快速修复会移除冗余的容器为 null 性注解。
2026年 5月 8日