Skip to content

Adding Annotations for ReSharper Code Inspection #15

@BrunoJuchli

Description

@BrunoJuchli

Hi
Given the following code:

public static class ForEachExtensions
{
    public static void ForEach<T>(this IEnumerable<T> enumerable, Action<T> action)
    {
        Guard.That(() => enumerable).IsNotNull();
        Guard.That(() => action).IsNotNull();

        foreach (T item in enumerable)
        {
            action(item);
        }
    }
}

ReSharper will warn us of "Possible multiple enumeration of IEnumerable". This is because - of course - ReSharper does not know whether the external .That() method is actually enumerating the IEnumerable or not.
However we can tell ReSharper that the That() method is not enumerating the IEnumerable. This can be done either by adding attributes to the implementation of Seterlund.CodeGuard or by adding an an XML file besides the Seterlund.CodeGuard.dll. The attributes don't require to reference a JetBrains library or the likes. Also see http://www.jetbrains.com/resharper/webhelp/Code_Analysis__Code_Annotations.html

Given that the code attributes don't require any external dependency and they clutter the code only a little, i think it might be a viable alternative. It would certainly be easiest to maintain. So at this point i personally would prefer this, but of course, the external XML annotations are good enough, too.

Would you accept a pull request for this feature and if so, which method would you prefer?

btw. Thank you for the great library! :)

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