集合访问分析
Besides analyzing values of collection items, ReSharper also analyzes each collection you use as a whole — it warns you when a collection is never filled or modified even if there is read access to this collection:

或者,如果集合从未被读取:

默认情况下,所有标准集合类型都会以这种方式进行分析。 如果需要,您还可以将此分析应用于从 IEnumerable 派生的自定义集合。 在这种情况下,您需要告诉 ReSharper 集合公共方法的调用将如何影响集合的内容。 为此,请使用 [CollectionAccessAttribute]标记集合类的方法,该属性应具有以下四个标志之一: None、 Read、 ModifyExistingContent、 UpdatedContent (最后两个标志的区别在于 UpdatedContent 表示标记的函数还可以向集合中添加新元素)。 以下是一个简单的示例来说明这一点:

2026年 11月 6日