CSharpEssentials icon indicating copy to clipboard operation
CSharpEssentials copied to clipboard

Add null-ckeck analyzer and code fix

Open s-arash opened this issue 8 years ago • 5 comments

-Add the analyzer and code fix classes -Add related unit tests -Modify readme.md to showcase the new feature

The analyzer looks for cases like this:

if ( handle != null) handle.Dispose();

and the code fix converts them to:

handle?.Dispose();

It recognizes more complex syntax too.

if ( repo.Customers != null) repo.Customers[0].Orders.Verify();

--->

repo.Customers?[0].Orders.Verify();

s-arash avatar May 10 '16 20:05 s-arash

@s-arash, my apologies for not getting to this sooner! FWIW, we actually delivered this feature in the last update to Visual Studio 2015. So, you shouldn't need it C# Essentials.

DustinCampbell avatar Jun 06 '16 23:06 DustinCampbell

@DustinCampbell as far as I know, Visual Studio only looks for delegate invocation

if (SomethingHappened != null) SomethingHappened(this, args); 
// -->
SomethingHappened?.Invoke(this,args);

This code fix looks for other cases where null conditional access can be used to simplify code. Unless I'm missing something obvious, that is the situation.

s-arash avatar Jun 07 '16 05:06 s-arash

Ah yes, you are correct. Sorry about that!

DustinCampbell avatar Jun 07 '16 13:06 DustinCampbell

No problem!

s-arash avatar Jun 07 '16 15:06 s-arash

Is this going to get merged in?!

normanhh3 avatar Mar 09 '17 03:03 normanhh3