Mark method as not enumerable
I have a code that is checking something if it's not null. It works like Code Contracts (They doesn't work in my project so I use my own implementation).
So for example my test method is:
public static void IsNotNull<T>(this T obj, string argName = null) where T : class
{
if (obj != null)
return;
if (argName == null)
throw new ArgumentNullException();
throw new ArgumentNullException(argName);
}
then I call it somewhere:
source.IsNotNull("source");
foreach (T value in source) // working with source
and resharper warns "Possible NullReferenceException". I don't want to turn off this check but I also don't want to get spammed by this message. I tried to apply Code Annotations, but they doesn't work. I want to say "Hey, R#, this code doesn't enumerate collection so don't worry about this call".
Please sign in to leave a comment.
"NoEnumeration" attribute can be applied to parameter "obj" in "IsNotNull" declaration.
Can we please get the opposite of this?
I'm really tried of resharper warning about multiple enumerations when I return a foo.ToList() as IEnumerable<Foo> and not ICollection<Foo>.
Maybe something like [PureEnumerable] [ListEnumerable] [NoSideEffects] [SafeEnumerable] [MultiEnumerable] etc
I've created feature request for this:
https://youtrack.jetbrains.com/issue/RSRP-454206
Thanks Ivan!