@@ -13,7 +13,7 @@ namespace Microsoft.VisualStudio.ProjectSystem.Properties;
1313[ ExportDynamicEnumValuesProvider ( "StartupObjectsEnumProvider" ) ]
1414[ AppliesTo ( ProjectCapability . CSharpOrVisualBasic ) ]
1515[ method: ImportingConstructor ]
16- internal class StartupObjectsEnumProvider ( [ Import ( typeof ( VisualStudioWorkspace ) ) ] Workspace workspace , UnconfiguredProject project ) : IDynamicEnumValuesProvider
16+ internal sealed class StartupObjectsEnumProvider ( [ Import ( typeof ( VisualStudioWorkspace ) ) ] Workspace workspace , UnconfiguredProject project ) : IDynamicEnumValuesProvider
1717{
1818 public Task < IDynamicEnumValuesGenerator > GetProviderAsync ( IList < NameValuePair > ? options )
1919 {
@@ -35,57 +35,57 @@ public Task<IDynamicEnumValuesGenerator> GetProviderAsync(IList<NameValuePair>?
3535
3636 return Task . FromResult < IDynamicEnumValuesGenerator > ( new StartupObjectsEnumGenerator ( workspace , project , includeEmptyValue , searchForEntryPointsInFormsOnly ) ) ;
3737 }
38- }
39-
40- internal class StartupObjectsEnumGenerator ( Workspace workspace , UnconfiguredProject unconfiguredProject , bool includeEmptyValue , bool searchForEntryPointsInFormsOnly ) : IDynamicEnumValuesGenerator
41- {
42- public bool AllowCustomValues => true ;
4338
44- public async Task < ICollection < IEnumValue > > GetListedValuesAsync ( )
39+ private sealed class StartupObjectsEnumGenerator ( Workspace workspace , UnconfiguredProject unconfiguredProject , bool includeEmptyValue , bool searchForEntryPointsInFormsOnly ) : IDynamicEnumValuesGenerator
4540 {
46- Project ? project = workspace . CurrentSolution . Projects . FirstOrDefault ( p => PathHelper . IsSamePath ( p . FilePath ! , unconfiguredProject . FullPath ) ) ;
41+ public bool AllowCustomValues => true ;
4742
48- if ( project is null )
43+ public async Task < ICollection < IEnumValue > > GetListedValuesAsync ( )
4944 {
50- return [ ] ;
51- }
45+ Project ? project = workspace . CurrentSolution . Projects . FirstOrDefault ( p => PathHelper . IsSamePath ( p . FilePath ! , unconfiguredProject . FullPath ) ) ;
5246
53- Compilation ? compilation = await project . GetCompilationAsync ( ) ;
47+ if ( project is null )
48+ {
49+ return [ ] ;
50+ }
5451
55- if ( compilation is null )
56- {
57- // Project does not support compilations
58- return [ ] ;
59- }
52+ Compilation ? compilation = await project . GetCompilationAsync ( ) ;
6053
61- List < IEnumValue > enumValues = [ ] ;
62- if ( includeEmptyValue )
63- {
64- enumValues . Add ( new PageEnumValue ( new EnumValue { Name = string . Empty , DisplayName = VSResources . StartupObjectNotSet } ) ) ;
65- }
54+ if ( compilation is null )
55+ {
56+ // Project does not support compilations
57+ return [ ] ;
58+ }
6659
67- IEntryPointFinderService ? entryPointFinderService = project . Services . GetService < IEntryPointFinderService > ( ) ;
60+ List < IEnumValue > enumValues = [ ] ;
61+ if ( includeEmptyValue )
62+ {
63+ enumValues . Add ( new PageEnumValue ( new EnumValue { Name = string . Empty , DisplayName = VSResources . StartupObjectNotSet } ) ) ;
64+ }
6865
69- IEnumerable < INamedTypeSymbol > ? entryPoints = entryPointFinderService ? . FindEntryPoints ( compilation . GlobalNamespace , searchForEntryPointsInFormsOnly ) ;
66+ IEntryPointFinderService ? entryPointFinderService = project . Services . GetService < IEntryPointFinderService > ( ) ;
7067
71- if ( entryPoints is not null )
72- {
73- enumValues . AddRange ( entryPoints . Select ( ep =>
68+ IEnumerable < INamedTypeSymbol > ? entryPoints = entryPointFinderService ? . FindEntryPoints ( compilation . GlobalNamespace , searchForEntryPointsInFormsOnly ) ;
69+
70+ if ( entryPoints is not null )
7471 {
75- string name = ep . ToDisplayString ( SymbolDisplayFormat . FullyQualifiedFormat . WithGlobalNamespaceStyle ( SymbolDisplayGlobalNamespaceStyle . Omitted ) ) ;
76- return new PageEnumValue ( new EnumValue { Name = name , DisplayName = name } ) ;
77- } ) ) ;
78- }
72+ enumValues . AddRange ( entryPoints . Select ( ep =>
73+ {
74+ string name = ep . ToDisplayString ( SymbolDisplayFormat . FullyQualifiedFormat . WithGlobalNamespaceStyle ( SymbolDisplayGlobalNamespaceStyle . Omitted ) ) ;
75+ return new PageEnumValue ( new EnumValue { Name = name , DisplayName = name } ) ;
76+ } ) ) ;
77+ }
7978
80- // Remove My.MyApplication entry if any.
81- enumValues . RemoveAll ( ep => ep . Name . Contains ( "My.MyApplication" ) ) ;
79+ // Remove My.MyApplication entry if any.
80+ enumValues . RemoveAll ( ep => ep . Name . Contains ( "My.MyApplication" ) ) ;
8281
83- return enumValues ;
84- }
82+ return enumValues ;
83+ }
8584
86- public Task < IEnumValue ? > TryCreateEnumValueAsync ( string userSuppliedValue )
87- {
88- var value = new PageEnumValue ( new EnumValue { Name = userSuppliedValue , DisplayName = userSuppliedValue } ) ;
89- return Task . FromResult < IEnumValue ? > ( value ) ;
85+ public Task < IEnumValue ? > TryCreateEnumValueAsync ( string userSuppliedValue )
86+ {
87+ var value = new PageEnumValue ( new EnumValue { Name = userSuppliedValue , DisplayName = userSuppliedValue } ) ;
88+ return Task . FromResult < IEnumValue ? > ( value ) ;
89+ }
9090 }
9191}
0 commit comments