BUG: doesn't recognize custom IsNullOrEmpty extension method
We have a generic extension method that we use for null checks. We still receive the "Possible System.NullReferenceException" when the extension method is used.
Extension Method:
public static bool IsNullOrEmpty<T>(this IEnumerable<T> target)
{
bool flag = true;
if (target != null)
{
using (IEnumerator<T> enumerator = target.GetEnumerator())
{
if (enumerator.MoveNext())
{
T current = enumerator.Current;
flag = false;
}
}
}
return flag;
}
Please sign in to leave a comment.
Hello!
Thank you for the feedback.
Could you please provide also code sample demonstrating "Possible System.NullReferenceException" when the extension method is used?
Thanks in advance.
I suspect you'll need to add the ContractAnnotation attribute to the method.
[ContractAnnotation("null => true")]public static bool IsNullOrEmpty<T>(this IEnumerable<T> target)
Is there any way to do this with Null Checking Patterns so that we are not dependent on annotations?
I'll duplicate Richard's answer here: https://resharper-support.jetbrains.com/hc/en-us/community/posts/6722297112594/comments/6729176732050