Replace with IsEmpty inspection

I've noticed that I keep getting a warning for "Replace with IsEmpty()" which wants to change things like:

   if(collection.Count() > 1)

with
   if(collection.IsEmpty())

but when I do that, the IsEmpty() function is not resolvable, so I get an error.  What is this, is this something new to VS 2011/.NET 4.5?

7 comments
Comment actions Permalink

Hello Mark,

Could you please attach a screenshot demonstrating this suggestion? Thank
you!

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

I've noticed that I keep getting a warning for "Replace with
IsEmpty()" which wants to change things like:

if(collection.Count() > 1)

with
if(collection.IsEmpty())
but when I do that, the IsEmpty() function is not resolvable, so I get
an error.  What is this, is this something new to VS 2011/.NET 4.5?

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



0
Comment actions Permalink

Resharper should be suggesting changing

if(collection.Count() > 1)

to

if(collection.Any())

and

if(collection.Count() == 0)

to

if(!collection.Any())

which I'm sure it used to.

0
Comment actions Permalink

IsEmpty.png

This just started happening with R# 6.1.  I thought there was a new 'IsEmpty()' extension method that I was missing! :^O

0
Comment actions Permalink

There is an IsEmpty function for XElement.

http://msdn.microsoft.com/en-us/library/system.xml.linq.xelement.isempty%28v=vs.95%29.aspx

But I'm not aware of an extension method for what your screen capture is displaying.

0
Comment actions Permalink

That applies to the XElement class specifically, if you look closely at that code, the suggestion is on the documents variable which is of type IEnumerable<XElement>.  As I mentioned, if I take the suggestion, the IsEmpty is immediately highlighted (by R# ironically enough) as an error that indicates that IsEmpty cannot be resolved.

0
Comment actions Permalink

You got to that quick, I was in the middle of editing my post as I realised you were stating an extension for collections.

0
Comment actions Permalink

Hello Mark,

This is a bug and it should get fixed in the next EAP build. Thank you!

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

Image:IsEmpty.png

This just started happening with R# 6.1.  I thought there was a new
'IsEmpty()' extension method that I was missing!


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



0

Please sign in to leave a comment.