Skip to content

Change rule AV1130 (remove reference to .NET 4.5) #215

@pauljansen42

Description

@pauljansen42

Rule AV1130 states "Return an IEnumerable or ICollection instead of a concrete collection class". The intention of the rule is to make sure that no mutable collection classes are returned. However, ICollection is mutable. The only reason why it is mentioned in the rule is that users who run a .NET framework version lower than 4.5 have no other choice than to use ICollection.

Since almost everybody is using at least .NET framework 4.5 (distributed with Visual Studio 2012), I recommend to rephrase the rule and make it a bit stricter. So I suggest to rename the rule to:

Return unchangeable interface collection classes (AV1130)

And allow only

IEnumerable, IReadOnlyCollection, IReadOnlyList or IReadOnlyDictionary<TKey, TValue>, ImmutableArray, ImmutableList or ImmutableDictionary<TKey, TValue>

So without ICollection. The reason why I am asking this is because a lot of people ask us why ICollection is allowed because the rule states "You generally don’t want callers to be able to change an internal collection".

I have discussed this already with Dennis Doomen and he told me "Kan ik me op zich wel in vinden", which means "I can live with that".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions