1
- using System . Collections . Generic ;
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Diagnostics ;
2
4
using System . IO ;
3
5
using System . Linq ;
6
+ using System . Runtime . InteropServices ;
4
7
using Microsoft . Vbe . Interop ;
5
8
6
9
namespace Rubberduck . VBEditor . Extensions
@@ -9,22 +12,30 @@ public static class ProjectExtensions
9
12
{
10
13
public static string ProjectName ( this VBProject project )
11
14
{
12
- var projectName = project . Name ;
13
- if ( project . Protection == vbext_ProjectProtection . vbext_pp_none )
15
+ var projectName = string . Empty ;
16
+ try
14
17
{
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 )
20
20
{
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 )
23
26
{
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
+ }
25
32
}
26
33
}
27
34
}
35
+ catch ( COMException exception )
36
+ {
37
+ Debug . WriteLine ( exception ) ;
38
+ }
28
39
return projectName ;
29
40
}
30
41
0 commit comments