ReSharper 2026.1 Help

代码检查:在非容器类型声明中使用容器可空性属性

该检查会报告将容器项 可空性注解应用于没有可空项的类型。

典型示例包括在值类型或其他非容器声明上使用 [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; }

快速修复

快速修复会移除多余的容器可空性注解。

2026年 5月 8日