"Possible Null Reference".
I have a validation routine that insures an object is valid. However ReSharper is not aware (of course) of what my routine does. Therefore
SomeClass c = o as SomeClass; // "c" may be null for a variety of reasons.
PreCondition.IsNotNull(c); // My Validator - This will throw if c is null
c.SomeMethod(); // Resharper still reports possible null reference.
If there a simple means of informin resharper that "PreCondition.IsNotNull" will make sure the reference is NOT null, and therefore the warning should be suppressed...
Please sign in to leave a comment.
Hello,
JetBrains.Annotations.AssertionMethodAttribute on the method and JetBrains.Annotations.AssertionConditionAttribute
on the parameter might help.
—
Serge Baltic
JetBrains, Inc — http://www.jetbrains.com
“Develop with pleasure!”
The only way I would see to do that would be if you had you IsNotNull checker return the object, so you would get:
c = PreCondition.IsNotNull(c);
You could mark the IsNotNull return value as using JetBrainsAnnotations and the problem would be solved. You owuld have an extra assignment in you IL code.
It's kind of a weird approach in any event. Won't the throw in IsNotNull be just the same and as informative as if you had just let the framework throw a NullReferenceException?
Thanks for the information on the annotations, I will look into them again (they did not seem to work in previous attempts).
(Not overly material but...) The PreCondition suite embodies a significan amount of logic and wraps the "actual" exception into a "PreConditionException" this allows for a single catch structure at the highest levels of the code to catch all exceptions which are the direct result of a condition indicitive of a development bug. It also has a significant amount of logging to facilitate diagnostics. By trapping the condifion BEFORE anything is unwound, the complete application state can be captured intact.