Suggestion for new rule: string.IsNullOrEmpty

When having something like:

if ( myString == null || myString.Length <= 0 )

resp.

if ( myString == null || myString.Length = 0 )

ReSharper could suggest to replace it with

if ( string.IsNullOrEmpty( myString ) )

3 comments
Comment actions Permalink

Hello Uwe,

There is context action to do that. It is available on "||" operator. Not
very discoverable, I know :) We are going to find better solution to this.

Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


UK> When having something like:
UK>
UK> if ( myString == null || myString.Length <= 0 )
UK>
UK> resp.
UK>
UK> if ( myString == null || myString.Length = 0 )
UK>
UK> ReSharper could suggest to replace it with
UK>
UK> if ( string.IsNullOrEmpty( myString ) )
UK>


0
Comment actions Permalink

Found it :)

Thank you!

Cheers
Uwe (http://magerquark.com)

0
Comment actions Permalink

One more addition:

if ( myString != null && myString.Length > 0 )

i.e. the opposite is not yet detected but could be as:

if ( !string.IsNullOrEmpty( myString ) )

Cheers
Uwe

0

Please sign in to leave a comment.