Skip to content

Commit 371496a

Browse files
committed
Fix chained COM wrappers
1 parent b116a65 commit 371496a

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

Rubberduck.CodeAnalysis/Inspections/Concrete/SheetAccessedUsingStringInspection.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
6060
var component = GetVBComponentMatchingSheetName(reference);
6161
if (component != null)
6262
{
63-
reference.Properties.CodeName = (string)component.Properties.Single(property => property.Name == "CodeName").Value;
63+
using (var properties = component.Properties)
64+
{
65+
reference.Properties.CodeName = (string)properties.Single(property => property.Name == "CodeName").Value;
66+
}
6467
issues.Add(reference);
6568
}
6669
}
@@ -98,9 +101,28 @@ private IVBComponent GetVBComponentMatchingSheetName(IdentifierReferenceInspecti
98101
var sheetName = FormatSheetName(sheetArgumentContext.GetText());
99102
var project = State.Projects.First(p => p.ProjectId == reference.QualifiedName.ProjectId);
100103

101-
return project.VBComponents.FirstOrDefault(c =>
102-
c.Type == ComponentType.Document &&
103-
(string) c.Properties.First(property => property.Name == "Name").Value == sheetName);
104+
using (var components = project.VBComponents)
105+
{
106+
for (var i = 0; i < components.Count; i++)
107+
{
108+
using (var component = components[i])
109+
using (var properties = component.Properties)
110+
{
111+
for (var j = 0; j < properties.Count; j++)
112+
{
113+
using (var property = properties[j])
114+
{
115+
if (component.Type == ComponentType.Document && property.Name == "Name" && (string)property.Value == sheetName)
116+
{
117+
return component;
118+
}
119+
}
120+
}
121+
}
122+
}
123+
124+
return null;
125+
}
104126
}
105127

106128
private static string FormatSheetName(string sheetName)

0 commit comments

Comments
 (0)