How do I customize inspections to recognize a custom method for checking for nulls?
We have several library functions and extension methods like .IsEmpty() or .IsEmptyOrNull(). When we use them, Rider/Resharper always flags the code underneath for possible null reference exceptions, like for the code below will flag myObject.DoSomething() as a possible null reference exception.
How do I configure the inspections to recognize my methods as null reference checks?
if (!myObject.IsEmptyOrNull())
{
myObject.DoSomething();
}
Please sign in to leave a comment.
Hello Chris Palmer, thank you for your questions. You need to mark your extension method with the following annotation (from JetBrains.Annotations package):
Please let me know if you have any questions. Thank you!
That works well, but a few of the methods are in a library that we can't modify to annotate. Anything in the inspection configuration that could be set to do the same thing?
Please take a look at External Annotations, it should help in your case.