Skip to content

Conversation

s-arash
Copy link

@s-arash s-arash commented May 10, 2016

-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 added 2 commits May 11, 2016 01:03
 -Add the analyzer and code fix classes
 -Add related unit tests
 -Modify readme.md to showcase the new feature
@DustinCampbell
Copy link
Owner

@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.

@s-arash
Copy link
Author

s-arash commented Jun 7, 2016

@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.

@DustinCampbell
Copy link
Owner

Ah yes, you are correct. Sorry about that!

<Reference Include="Microsoft.CodeAnalysis.Workspaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.0.0\lib\net45\Microsoft.CodeAnalysis.Workspaces.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad. Fixed it.

…ols.UnitTestFramework that somehow snuck in.
@s-arash
Copy link
Author

s-arash commented Jun 7, 2016

No problem!

@normanhh3
Copy link

Is this going to get merged in?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants