Skip to content

Gendarme.Rules.Design.Generic.ImplementGenericCollectionInterfacesRule(git)

Sebastien Pouliot edited this page Mar 2, 2011 · 1 revision

ImplementGenericCollectionInterfacesRule

Assembly: Gendarme.Rules.Design.Generic
Version: git

Description

This rule checks for types which implement the non-generic System.IEnumerable interface but not the [[System.IEnumerable<T>|http://msdn.microsoft.com/library/System.IEnumerable.aspx]] interface. Implementing the generic version of System.IEnumerable avoids casts, and possibly boxing, when iterating the collection.

Examples

Bad example:

public class IntEnumerable : IEnumerable {
    public IEnumerator GetEnumerator ()
    {
    }
}

Good example:

public class IntEnumerable : IEnumerable<int> {
    public IEnumerator<int> GetEnumerator ()
    {
    }
    IEnumerator IEnumerable.GetEnumerator ()
    {
    }
}

Notes

  • This rule applies only to assemblies targeting .NET 2.0 and later.

Source code

You can browse the latest source code of this rule on github.com

Clone this wiki locally