Skip to content

Commit acb999b

Browse files
committed
Fix chained calls
1 parent 6218bad commit acb999b

File tree

18 files changed

+73
-33
lines changed

18 files changed

+73
-33
lines changed

Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerComponentViewModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ public CodeExplorerComponentViewModel(CodeExplorerItemViewModel parent, Declarat
110110

111111
private bool ContainsBuiltinDocumentPropertiesProperty()
112112
{
113-
using (var properties = _projectsProvider.Component(Declaration.QualifiedName.QualifiedModuleName).Properties)
113+
using (var component = _projectsProvider.Component(Declaration.QualifiedName.QualifiedModuleName))
114+
using (var properties = component.Properties)
114115
{
115116
return properties.Any(item => item.Name == "BuiltinDocumentProperties");
116117
}

Rubberduck.Core/Navigation/RegexSearchReplace/RegexSearchReplace.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ private IEnumerable<RegexSearchResult> GetResultsFromModule(ICodeModule module,
8989

9090
private void SetSelection(RegexSearchResult item)
9191
{
92-
item.Module.CodePane.Selection = item.Selection;
92+
using (var module = item.Module)
93+
using (var codePane = module.CodePane)
94+
{
95+
codePane.Selection = item.Selection;
96+
}
9397
}
9498

9599
private List<RegexSearchResult> SearchSelection(string searchPattern)

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ protected override bool EvaluateCanExecute(object parameter)
3434

3535
try
3636
{
37-
using (var codeModule = _projectsProvider.Component(node.Declaration.QualifiedName.QualifiedModuleName).CodeModule)
37+
using (var component = _projectsProvider.Component(node.Declaration.QualifiedName.QualifiedModuleName))
38+
using (var codeModule = component.CodeModule)
3839
{
3940
return codeModule.CountOfLines != 0;
4041
}
@@ -55,10 +56,11 @@ protected override void OnExecute(object parameter)
5556
qualifiedComponentName.ComponentName + ".txt");
5657

5758
List<string> text;
58-
using (var codeModule = _projectsProvider.Component(qualifiedComponentName).CodeModule)
59+
using (var component = _projectsProvider.Component(qualifiedComponentName))
60+
using (var codeModule = component.CodeModule)
5961
{
6062
text = codeModule.GetLines(1, codeModule.CountOfLines)
61-
.Split(new[] {Environment.NewLine}, StringSplitOptions.None).ToList();
63+
.Split(new[] { Environment.NewLine }, StringSplitOptions.None).ToList();
6264
}
6365

6466
var printDoc = new PrintDocument { DocumentName = path };

Rubberduck.Core/UI/Command/AddTestMethodExpectedErrorCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ protected override void OnExecute(object parameter)
9393
{
9494
var declaration = _state.GetTestModules().FirstOrDefault(f =>
9595
{
96-
using (var thisModule = _state.ProjectsProvider.Component(f.QualifiedName.QualifiedModuleName).CodeModule)
96+
using (var component = _state.ProjectsProvider.Component(f.QualifiedName.QualifiedModuleName))
97+
using (var thisModule = component.CodeModule)
9798
{
9899
return thisModule.Equals(activeModule);
99100
}

Rubberduck.Core/UI/Command/FindAllImplementationsCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ private SearchResultsViewModel CreateViewModel(Declaration target)
173173

174174
private string GetModuleLine(QualifiedModuleName module, int line)
175175
{
176-
using (var codeModule = _state.ProjectsProvider.Component(module).CodeModule)
176+
using (var component = _state.ProjectsProvider.Component(module))
177+
using (var codeModule = component.CodeModule)
177178
{
178179
return codeModule.GetLines(line, 1).Trim();
179180
}

Rubberduck.Core/UI/Command/FindAllReferencesCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ private SearchResultsViewModel CreateViewModel(Declaration declaration)
177177

178178
private string GetModuleLine(QualifiedModuleName module, int line)
179179
{
180-
using (var codeModule = _state.ProjectsProvider.Component(module).CodeModule)
180+
using (var component = _state.ProjectsProvider.Component(module))
181+
using (var codeModule = component.CodeModule)
181182
{
182183
return codeModule.GetLines(line, 1).Trim();
183184
}

Rubberduck.Core/UI/Command/MenuItems/CommandBars/RubberduckCommandBar.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ private void OnSelectionChange(object sender, DeclarationChangedEventArgs e)
6464
if (string.IsNullOrEmpty(caption) && e.VBComponent != null)
6565
{
6666
//Fallback caption for selections in the Project window.
67-
caption = $"{e.VBComponent.ParentProject.Name}.{e.VBComponent.Name} ({e.VBComponent.Type})";
67+
using (var parentProject = e.VBComponent.ParentProject)
68+
{
69+
caption = $"{parentProject.Name}.{e.VBComponent.Name} ({e.VBComponent.Type})";
70+
}
6871
}
6972

7073
var refCount = e.Declaration?.References.Count() ?? 0;

Rubberduck.Core/UI/Command/NavigateCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ protected override void OnExecute(object parameter)
3131

3232
try
3333
{
34-
using (var codeModule = _projectsProvider.Component(param.QualifiedName).CodeModule)
34+
using (var component = _projectsProvider.Component(param.QualifiedName))
35+
using (var codeModule = component.CodeModule)
3536
{
3637
using (var codePane = codeModule.CodePane)
3738
{

Rubberduck.Core/UI/IdentifierReferences/IdentifierReferencesListDockablePresenter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ private void BindTarget(Declaration target)
3131

3232
private void OnNavigateIdentifierReference(IdentifierReference reference)
3333
{
34-
using (var codeModule = _projectsProvider.Component(reference.QualifiedModuleName).CodeModule)
34+
using (var component = _projectsProvider.Component(reference.QualifiedModuleName))
35+
using (var codeModule = component.CodeModule)
3536
{
3637
using (var codePane = codeModule.CodePane)
3738
{

Rubberduck.Core/UI/IdentifierReferences/ImplementationsListDockablePresenter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ private void BindTarget(IEnumerable<Declaration> implementations)
3333

3434
private void OnNavigateImplementation(Declaration implementation)
3535
{
36-
using (var codeModule = _projectsProvider.Component(implementation.QualifiedName.QualifiedModuleName).CodeModule)
36+
using (var component = _projectsProvider.Component(implementation.QualifiedName.QualifiedModuleName))
37+
using (var codeModule = component.CodeModule)
3738
{
3839
using (var codePane = codeModule.CodePane)
3940
{

0 commit comments

Comments
 (0)