CSharpEssentials
CSharpEssentials copied to clipboard
Add null-ckeck analyzer and code fix
-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, 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 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.
Ah yes, you are correct. Sorry about that!
No problem!
Is this going to get merged in?!