Skip to content

Commit 1dd686f

Browse files
committed
Rearrange Dispose methods to make MS happy. Addresses CA1063
1 parent 9fa002d commit 1dd686f

File tree

84 files changed

+522
-72
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+522
-72
lines changed

Rubberduck.CodeAnalysis/Inspections/Inspector.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,25 @@ private bool IsDisabled(CodeInspectionSettings config, IInspection inspection)
250250

251251
public void Dispose()
252252
{
253+
Dispose(true);
254+
GC.SuppressFinalize(this);
255+
}
256+
257+
private bool _isDisposed;
258+
protected virtual void Dispose(bool disposing)
259+
{
260+
if (_isDisposed || !disposing)
261+
{
262+
return;
263+
}
264+
253265
if (_configService != null)
254266
{
255267
_configService.SettingsChanged -= ConfigServiceSettingsChanged;
256268
}
257269

258-
_inspections.Clear();
270+
_inspections.Clear();
271+
_isDisposed = true;
259272
}
260273
}
261274
}

Rubberduck.Core/AppMenu.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ public void Localize()
7171

7272
public void Dispose()
7373
{
74+
Dispose(true);
75+
GC.SuppressFinalize(this);
76+
}
77+
78+
private bool _isDisposed;
79+
protected virtual void Dispose(bool disposing)
80+
{
81+
if (_isDisposed || !disposing)
82+
{
83+
return;
84+
}
85+
_isDisposed = true;
86+
7487
_parser.State.StateChanged -= OnParserStateChanged;
7588
_selectionService.SelectedDeclarationChanged -= OnSelectedDeclarationChange;
7689

Rubberduck.Core/AutoComplete/Service/AutoCompleteService.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,19 @@ private void HandleKeyDown(object sender, AutoCompleteEventArgs e)
147147

148148
public void Dispose()
149149
{
150+
Dispose(true);
151+
GC.SuppressFinalize(this);
152+
}
153+
154+
private bool _isDisposed;
155+
protected virtual void Dispose(bool disposing)
156+
{
157+
if (_isDisposed || !disposing)
158+
{
159+
return;
160+
}
161+
_isDisposed = true;
162+
150163
Disable();
151164
if (_configService != null)
152165
{

Rubberduck.Core/CodeAnalysis/CodeMetrics/CodeMetricsViewModel.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,19 @@ private void UpdateNodes(IEnumerable<CodeExplorerItemViewModel> oldList, IEnumer
120120

121121
public void Dispose()
122122
{
123+
Dispose(true);
124+
GC.SuppressFinalize(this);
125+
}
126+
127+
private bool _isDisposed;
128+
protected virtual void Dispose(bool disposing)
129+
{
130+
if (_isDisposed || !disposing)
131+
{
132+
return;
133+
}
134+
_isDisposed = true;
135+
123136
_state.StateChanged -= OnStateChanged;
124137
}
125138

Rubberduck.Core/UI/CodeExplorer/Commands/ExportCommand.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,20 @@ protected override void OnExecute(object parameter)
7272

7373
public void Dispose()
7474
{
75-
if (_saveFileDialog != null)
75+
Dispose(true);
76+
GC.SuppressFinalize(this);
77+
}
78+
79+
private bool _isDisposed;
80+
protected virtual void Dispose(bool disposing)
81+
{
82+
if (_isDisposed || !disposing)
7683
{
77-
_saveFileDialog.Dispose();
84+
return;
7885
}
86+
87+
_saveFileDialog?.Dispose();
88+
_isDisposed = true;
7989
}
8090
}
8191
}

Rubberduck.Core/UI/CodeExplorer/Commands/ImportCommand.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,20 @@ private IVBProject GetNodeProject(CodeExplorerItemViewModel parameter)
121121

122122
public void Dispose()
123123
{
124-
if (_openFileDialog != null)
124+
Dispose(true);
125+
GC.SuppressFinalize(this);
126+
}
127+
128+
private bool _isDisposed;
129+
protected virtual void Dispose(bool disposing)
130+
{
131+
if (_isDisposed || !disposing)
125132
{
126-
_openFileDialog.Dispose();
133+
return;
127134
}
135+
136+
_openFileDialog?.Dispose();
137+
_isDisposed = true;
128138
}
129139
}
130140
}

Rubberduck.Core/UI/CodeExplorer/Commands/RemoveCommand.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,20 @@ private bool ExportFile(CodeExplorerComponentViewModel node)
9696

9797
public void Dispose()
9898
{
99-
if (_saveFileDialog != null)
99+
Dispose(true);
100+
GC.SuppressFinalize(this);
101+
}
102+
103+
private bool _isDisposed;
104+
protected virtual void Dispose(bool disposing)
105+
{
106+
if (_isDisposed || !disposing)
100107
{
101-
_saveFileDialog.Dispose();
108+
return;
102109
}
110+
111+
_saveFileDialog?.Dispose();
112+
_isDisposed = true;
103113
}
104114
}
105115
}

Rubberduck.Core/UI/CodeExplorer/Commands/RenameCommand.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,20 @@ protected override void OnExecute(object parameter)
4444

4545
public void Dispose()
4646
{
47+
Dispose(true);
48+
GC.SuppressFinalize(this);
49+
}
50+
51+
private bool _isDisposed;
52+
protected virtual void Dispose(bool disposing)
53+
{
54+
if (_isDisposed || !disposing)
55+
{
56+
return;
57+
}
58+
4759
_view?.Dispose();
60+
_isDisposed = true;
4861
}
4962
}
5063
}

Rubberduck.Core/UI/Command/FindAllImplementationsCommand.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,23 @@ private Declaration FindTarget(object parameter)
210210

211211
public void Dispose()
212212
{
213+
Dispose(true);
214+
GC.SuppressFinalize(this);
215+
}
216+
217+
private bool _isDisposed;
218+
protected virtual void Dispose(bool disposing)
219+
{
220+
if (_isDisposed || !disposing)
221+
{
222+
return;
223+
}
224+
213225
if (_state != null)
214226
{
215227
_state.StateChanged -= _state_StateChanged;
216228
}
229+
_isDisposed = true;
217230
}
218231
}
219232
}

Rubberduck.Core/UI/Command/FindAllReferencesCommand.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,25 @@ private Declaration FindFormDesignerTarget(QualifiedModuleName qualifiedModuleNa
269269
return null;
270270
}
271271

272-
273272
public void Dispose()
274273
{
274+
Dispose(true);
275+
GC.SuppressFinalize(this);
276+
}
277+
278+
private bool _isDisposed;
279+
protected virtual void Dispose(bool disposing)
280+
{
281+
if (_isDisposed || !disposing)
282+
{
283+
return;
284+
}
285+
275286
if (_state != null)
276287
{
277288
_state.StateChanged -= _state_StateChanged;
278289
}
290+
_isDisposed = true;
279291
}
280292
}
281293
}

0 commit comments

Comments
 (0)