Skip to content

Commit 8412c36

Browse files
committed
fixed possible NRE's in QualifiedModuleName
1 parent 8a99e16 commit 8412c36

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

Rubberduck.VBEEditor/QualifiedModuleName.cs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,25 @@ private static string GetDisplayName(VBProject project)
5252
// Eg. A PowerPoint Slide is top level, but it's parent is a Presentation (that is NOT a vbComponent)
5353
try
5454
{
55-
var parentProp = project.VBComponents.Cast<VBComponent>()
55+
var firstOrDefault = project.VBComponents.Cast<VBComponent>()
5656
.FirstOrDefault(comp => comp.Type == vbext_ComponentType.vbext_ct_Document
57-
&& comp.Properties.Item("Parent").Value != null)
58-
.Properties.Cast<Property>().FirstOrDefault(property => property.Name == "Parent");
59-
60-
Properties props = null;
61-
Property nameProperty = null;
62-
if (parentProp.Value is Properties)
57+
&& comp.Properties.Item("Parent").Value != null);
58+
if (firstOrDefault != null)
6359
{
64-
props = (Properties)parentProp.Value;
65-
nameProperty = props.Cast<Property>().FirstOrDefault(property => property.Name == "Name");
60+
var parentProp = firstOrDefault
61+
.Properties.Cast<Property>().FirstOrDefault(property => property.Name == "Parent");
62+
63+
Property nameProperty = null;
64+
if (parentProp != null && parentProp.Value is Properties)
65+
{
66+
var props = (Properties)parentProp.Value;
67+
nameProperty = props.Cast<Property>().FirstOrDefault(property => property.Name == "Name");
68+
}
69+
70+
return nameProperty == null
71+
? null
72+
: nameProperty.Value.ToString();
6673
}
67-
68-
return nameProperty == null
69-
? null
70-
: nameProperty.Value.ToString();
7174
}
7275
catch
7376
{

0 commit comments

Comments
 (0)