Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule S4002: Disposable types should declare finalizer #327

Merged
merged 2 commits into from
May 18, 2017
Merged

Conversation

michalb-sonar
Copy link
Contributor

Fix #279

Copy link
Contributor

@valhristov valhristov left a comment

Choose a reason for hiding this comment

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

LGTM, minor changes needed

{
return classDeclaration.Members
.OfType<FieldDeclarationSyntax>()
.Select(m => semanticModel.GetDeclaredSymbol(m.Declaration.Variables.FirstOrDefault())?.GetSymbolType())
Copy link
Contributor

Choose a reason for hiding this comment

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

Call First() if you are sure there will be at least one variable.

return classDeclaration.Members
.OfType<FieldDeclarationSyntax>()
.Select(m => semanticModel.GetDeclaredSymbol(m.Declaration.Variables.FirstOrDefault())?.GetSymbolType())
.Any(si => si != null && si.IsAny(nativeHandles));
Copy link
Contributor

Choose a reason for hiding this comment

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

IsAny() checks for null

private IntPtr myResource;
private bool disposed = false;

protected virtual void Dispose(bool disposing)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would keep the test code as short as possible, e.g. keep only what's needed.

@michalb-sonar michalb-sonar merged commit 6616a62 into master May 18, 2017
@michalb-sonar michalb-sonar deleted the s4002 branch May 18, 2017 11:43
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.

2 participants