Skip to content

Commit cfef061

Browse files
committed
Merge pull request #1304 from retailcoder/next
fix for #1301
2 parents 037c73e + e026f8a commit cfef061

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

Rubberduck.VBEEditor/Extensions/VbProjectExtensions.cs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
24
using System.IO;
35
using System.Linq;
6+
using System.Runtime.InteropServices;
47
using Microsoft.Vbe.Interop;
58

69
namespace Rubberduck.VBEditor.Extensions
@@ -9,22 +12,30 @@ public static class ProjectExtensions
912
{
1013
public static string ProjectName(this VBProject project)
1114
{
12-
var projectName = project.Name;
13-
if (project.Protection == vbext_ProjectProtection.vbext_pp_none)
15+
var projectName = string.Empty;
16+
try
1417
{
15-
var documentModule = project
16-
.VBComponents.Cast<VBComponent>()
17-
.FirstOrDefault(item => item.Type == vbext_ComponentType.vbext_ct_Document);
18-
19-
if (documentModule != null)
18+
projectName = project.Name;
19+
if (project.Protection == vbext_ProjectProtection.vbext_pp_none)
2020
{
21-
var hostDocumentNameProperty = documentModule.Properties.Item("Name");
22-
if (hostDocumentNameProperty != null)
21+
var documentModule = project
22+
.VBComponents.Cast<VBComponent>()
23+
.FirstOrDefault(item => item.Type == vbext_ComponentType.vbext_ct_Document);
24+
25+
if (documentModule != null)
2326
{
24-
projectName += string.Format(" ({0})", hostDocumentNameProperty.Value);
27+
var hostDocumentNameProperty = documentModule.Properties.Item("Name");
28+
if (hostDocumentNameProperty != null)
29+
{
30+
projectName += string.Format(" ({0})", hostDocumentNameProperty.Value);
31+
}
2532
}
2633
}
2734
}
35+
catch (COMException exception)
36+
{
37+
Debug.WriteLine(exception);
38+
}
2839
return projectName;
2940
}
3041

0 commit comments

Comments
 (0)