Skip to content

Commit

Permalink
Added missing collection interfaces to AV1130 (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkoelman authored Feb 3, 2022
1 parent 7e170ac commit b71d0df
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion _rules/1130.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ rule_category: member-design
title: Return interfaces to unchangeable collections
severity: 2
---
You generally don't want callers to be able to change an internal collection, so don't return arrays, lists or other collection classes directly. Instead, return an `IEnumerable<T>`, `IReadOnlyCollection<T>`, `IReadOnlyList<T>` or `IReadOnlyDictionary<TKey, TValue>`.
You generally don't want callers to be able to change an internal collection, so don't return arrays, lists or other collection classes directly. Instead, return an `IEnumerable<T>`, `IAsyncEnumerable<T>`, `IReadOnlyCollection<T>`, `IReadOnlyList<T>`, `IReadOnlySet<T>` or `IReadOnlyDictionary<TKey, TValue>`.

**Exception:** Immutable collections such as `ImmutableArray<T>`, `ImmutableList<T>` and `ImmutableDictionary<TKey, TValue>` prevent modifications from the outside and are thus allowed.

0 comments on commit b71d0df

Please sign in to comment.