Wrong ToString hint

   see this: (using latest EAP build)
http://img135.imageshack.us/img135/1466/unledes.png

For example Sharepoint class SPFieldLookupValue returns null in ToString, when created with default constructor SPFieldLookupValue()

2 comments

Hello Martin,

At the moment 'ToString' method is annotated with NotNull attribute because
.ToString() is never expected to return null in .NET Framework. That's why
you get 'Expression is always false' warning as well as 'Possible assignment
to an entity marked with NotNull' on 'return null;' statement. You can avoid
this behavior by removing the annotation for 'ToString' from \ExternalAnnotations\mscorlib\mscorlib.4.0.0.0.Nullness.Generated.xml
(do not forget to restart all instance of ReSharper after doing this). Personally,
I think returning null from ToString is a very bad practice. Thank you!

Andrey Serebryansky
Senior Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

see this: (using latest EAP build)
Image:http://img135.imageshack.us/img135/1466/unledes.png
For example Sharepoint class SPFieldLookupValue returns null in
ToString, when created with default constructor SPFieldLookupValue()

---
Original message URL:
http://devnet.jetbrains.net/message/5304425#5304425




0

I agree that returning null in ToString is very bad idea (I don't do that in my code :) ), but unfortunately it is happening at least in one Micorosoft SharePoint core classes. Personally I would preffer accurate hint in this case instead of "expression always returns false" - The NotNull Attribute is only a hint, it's not guaranteed by compiler or languge itself, that all methods with such attributes could not return null value.

0

Please sign in to leave a comment.