Skip to content

Commit 57805ed

Browse files
committed
Convert to nested class
Also make private and sealed, doc and format.
1 parent 6813327 commit 57805ed

File tree

2 files changed

+46
-44
lines changed

2 files changed

+46
-44
lines changed

src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/StartupObjectsEnumProvider.cs

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/VisualBasic/SplashScreenEnumProvider.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
using Microsoft.VisualStudio.LanguageServices;
66
using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem;
77
using Microsoft.VisualStudio.ProjectSystem.Properties;
8-
using Project = Microsoft.CodeAnalysis.Project;
98

109
namespace Microsoft.VisualStudio.ProjectSystem.VS.Properties.VisualBasic;
1110

11+
/// <summary>
12+
/// Returns the set of splash screen forms in a project.
13+
/// </summary>
1214
[ExportDynamicEnumValuesProvider("SplashScreenEnumProvider")]
1315
[AppliesTo(ProjectCapability.VisualBasic)]
1416
[method: ImportingConstructor]
15-
internal class SplashScreenEnumProvider([Import(typeof(VisualStudioWorkspace))] Workspace workspace, UnconfiguredProject unconfiguredProject, ProjectProperties propertiesProvider) : IDynamicEnumValuesProvider
17+
internal sealed class SplashScreenEnumProvider([Import(typeof(VisualStudioWorkspace))] Workspace workspace, UnconfiguredProject unconfiguredProject, ProjectProperties propertiesProvider) : IDynamicEnumValuesProvider
1618
{
1719
public Task<IDynamicEnumValuesGenerator> GetProviderAsync(IList<NameValuePair>? options)
1820
{
@@ -27,10 +29,10 @@ public Task<IDynamicEnumValuesGenerator> GetProviderAsync(IList<NameValuePair>?
2729
&& bool.TryParse(pair.Value, out bool optionValue)
2830
&& optionValue) ?? false;
2931

30-
return Task.FromResult<IDynamicEnumValuesGenerator>(new SplashScreenEnumGenerator(workspace, unconfiguredProject, propertiesProvider, includeEmptyValue, true));
32+
return Task.FromResult<IDynamicEnumValuesGenerator>(new SplashScreenEnumGenerator(workspace, unconfiguredProject, propertiesProvider, includeEmptyValue, searchForEntryPointsInFormsOnly: true));
3133
}
3234

33-
internal class SplashScreenEnumGenerator(Workspace workspace, UnconfiguredProject unconfiguredProject, ProjectProperties properties, bool includeEmptyValue, bool searchForEntryPointsInFormsOnly) : IDynamicEnumValuesGenerator
35+
private sealed class SplashScreenEnumGenerator(Workspace workspace, UnconfiguredProject unconfiguredProject, ProjectProperties properties, bool includeEmptyValue, bool searchForEntryPointsInFormsOnly) : IDynamicEnumValuesGenerator
3436
{
3537
public bool AllowCustomValues => false;
3638

@@ -55,7 +57,7 @@ public async Task<ICollection<IEnumValue>> GetListedValuesAsync()
5557

5658
if (includeEmptyValue)
5759
{
58-
enumValues.Add(new PageEnumValue(new EnumValue { Name = string.Empty, DisplayName = VSResources.StartupObjectNotSet }));
60+
enumValues.Add(new PageEnumValue(new EnumValue { Name = "", DisplayName = VSResources.StartupObjectNotSet }));
5961
}
6062

6163
IEntryPointFinderService? entryPointFinderService = project.Services.GetService<IEntryPointFinderService>();

0 commit comments

Comments
 (0)