Skip to content

Commit a450cb6

Browse files
authored
Use file scoped namespaces (#38076)
* Use file scoped namespaces
1 parent b9fcd82 commit a450cb6

File tree

9,257 files changed

+948142
-957311
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

9,257 files changed

+948142
-957311
lines changed

Diff for: .config/dotnet-tools.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
]
1616
}
1717
}
18-
}
18+
}

Diff for: .editorconfig

+12-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ csharp_new_line_before_finally = true
4949
csharp_new_line_before_members_in_object_initializers = true
5050
csharp_new_line_before_members_in_anonymous_types = true
5151

52+
# Namespace settings
53+
csharp_style_namespace_declarations = file_scoped
54+
5255
[*.{xml,config,*proj,nuspec,props,resx,targets,yml,tasks}]
5356
indent_size = 2
5457

@@ -208,6 +211,9 @@ dotnet_diagnostic.IDE0044.severity = warning
208211
dotnet_diagnostic.IDE0073.severity = warning
209212
file_header_template = Licensed to the .NET Foundation under one or more agreements.\nThe .NET Foundation licenses this file to you under the MIT license.
210213

214+
# IDE0161: Convert to file-scoped namespace
215+
dotnet_diagnostic.IDE0161.severity = warning
216+
211217
[**/{test,samples,perf}/**.{cs,vb}]
212218
# CA1018: Mark attributes with AttributeUsageAttribute
213219
dotnet_diagnostic.CA1018.severity = suggestion
@@ -248,6 +254,11 @@ dotnet_diagnostic.CA2012.severity = suggestion
248254
# IDE0044: Make field readonly
249255
dotnet_diagnostic.IDE0044.severity = suggestion
250256

251-
252257
# CA2016: Forward the 'CancellationToken' parameter to methods that take one
253258
dotnet_diagnostic.CA2016.severity = suggestion
259+
260+
# Defaults for content in the shared src/ and shared runtime dir
261+
262+
[{**/Shared/runtime/**.{cs,vb},**/microsoft.extensions.hostfactoryresolver.sources/**.{cs,vb}}]
263+
# IDE0161: Convert to file-scoped namespace
264+
dotnet_diagnostic.IDE0161.severity = silent

Diff for: eng/tools/BaselineGenerator/Program.cs

+287-288
Large diffs are not rendered by default.

Diff for: eng/tools/RepoTasks/CreateFrameworkListFile.cs

+105-107
Original file line numberDiff line numberDiff line change
@@ -10,136 +10,134 @@
1010
using Microsoft.Build.Framework;
1111
using Microsoft.Build.Utilities;
1212

13-
namespace RepoTasks
13+
namespace RepoTasks;
14+
15+
public class CreateFrameworkListFile : Microsoft.Build.Utilities.Task
1416
{
15-
public class CreateFrameworkListFile : Microsoft.Build.Utilities.Task
17+
/// <summary>
18+
/// Files to extract basic information from and include in the list.
19+
/// </summary>
20+
[Required]
21+
public ITaskItem[] Files { get; set; }
22+
23+
[Required]
24+
public string TargetFile { get; set; }
25+
26+
/// <summary>
27+
/// Extra attributes to place on the root node.
28+
///
29+
/// %(Identity): Attribute name.
30+
/// %(Value): Attribute value.
31+
/// </summary>
32+
public ITaskItem[] RootAttributes { get; set; }
33+
34+
public override bool Execute()
1635
{
17-
/// <summary>
18-
/// Files to extract basic information from and include in the list.
19-
/// </summary>
20-
[Required]
21-
public ITaskItem[] Files { get; set; }
22-
23-
[Required]
24-
public string TargetFile { get; set; }
25-
26-
/// <summary>
27-
/// Extra attributes to place on the root node.
28-
///
29-
/// %(Identity): Attribute name.
30-
/// %(Value): Attribute value.
31-
/// </summary>
32-
public ITaskItem[] RootAttributes { get; set; }
33-
34-
public override bool Execute()
35-
{
36-
XAttribute[] rootAttributes = RootAttributes
37-
?.Select(item => new XAttribute(item.ItemSpec, item.GetMetadata("Value")))
38-
.ToArray();
36+
XAttribute[] rootAttributes = RootAttributes
37+
?.Select(item => new XAttribute(item.ItemSpec, item.GetMetadata("Value")))
38+
.ToArray();
3939

40-
var frameworkManifest = new XElement("FileList", rootAttributes);
40+
var frameworkManifest = new XElement("FileList", rootAttributes);
4141

42-
var usedFileProfiles = new HashSet<string>();
42+
var usedFileProfiles = new HashSet<string>();
4343

44-
foreach (var f in Files
45-
.Select(item => new
46-
{
47-
Item = item,
48-
Filename = Path.GetFileName(item.ItemSpec),
49-
AssemblyName = FileUtilities.GetAssemblyName(item.ItemSpec),
50-
FileVersion = FileUtilities.GetFileVersion(item.ItemSpec),
51-
IsNative = item.GetMetadata("IsNativeImage") == "true",
52-
IsSymbolFile = item.GetMetadata("IsSymbolFile") == "true",
53-
PackagePath = GetPackagePath(item)
54-
})
55-
.Where(f =>
56-
!f.IsSymbolFile &&
57-
(f.Filename.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) || f.IsNative))
58-
.OrderBy(f => f.Filename, StringComparer.Ordinal))
44+
foreach (var f in Files
45+
.Select(item => new
46+
{
47+
Item = item,
48+
Filename = Path.GetFileName(item.ItemSpec),
49+
AssemblyName = FileUtilities.GetAssemblyName(item.ItemSpec),
50+
FileVersion = FileUtilities.GetFileVersion(item.ItemSpec),
51+
IsNative = item.GetMetadata("IsNativeImage") == "true",
52+
IsSymbolFile = item.GetMetadata("IsSymbolFile") == "true",
53+
PackagePath = GetPackagePath(item)
54+
})
55+
.Where(f =>
56+
!f.IsSymbolFile &&
57+
(f.Filename.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) || f.IsNative))
58+
.OrderBy(f => f.Filename, StringComparer.Ordinal))
59+
{
60+
string path = Path.Combine(f.PackagePath, f.Filename).Replace('\\', '/');
61+
string type = f.IsNative ? "Native" : "Managed";
62+
var element = new XElement("File", new XAttribute("Path", path));
63+
64+
if (path.StartsWith("analyzers/", StringComparison.Ordinal))
5965
{
60-
string path = Path.Combine(f.PackagePath, f.Filename).Replace('\\', '/');
61-
string type = f.IsNative ? "Native" : "Managed";
62-
var element = new XElement("File", new XAttribute("Path", path));
66+
type = "Analyzer";
6367

64-
if (path.StartsWith("analyzers/", StringComparison.Ordinal))
68+
if (path.EndsWith(".resources.dll", StringComparison.Ordinal))
6569
{
66-
type = "Analyzer";
67-
68-
if (path.EndsWith(".resources.dll", StringComparison.Ordinal))
69-
{
70-
// omit analyzer resources
71-
continue;
72-
}
73-
74-
var pathParts = path.Split('/');
75-
76-
if (pathParts.Length < 3 || !pathParts[1].Equals("dotnet", StringComparison.Ordinal) || pathParts.Length > 5)
77-
{
78-
Log.LogError($"Unexpected analyzer path format {path}. Expected 'analyzers/dotnet(/roslyn<version>)(/language)/analyzer.dll");
79-
}
80-
81-
// Check if we have enough parts for language directory and include it.
82-
// There could be a roslyn<version> folder before the language folder. Check for it.
83-
bool hasRoslynVersion = pathParts[2].StartsWith("roslyn", StringComparison.Ordinal);
84-
int languageLengthCheck = hasRoslynVersion ? 4 : 3;
85-
int potentialLanguageIndex = hasRoslynVersion ? 3 : 2;
86-
if (pathParts.Length > languageLengthCheck)
87-
{
88-
element.Add(new XAttribute("Language", pathParts[potentialLanguageIndex]));
89-
}
70+
// omit analyzer resources
71+
continue;
9072
}
9173

92-
element.Add(new XAttribute("Type", type));
74+
var pathParts = path.Split('/');
9375

94-
if (f.AssemblyName != null)
76+
if (pathParts.Length < 3 || !pathParts[1].Equals("dotnet", StringComparison.Ordinal) || pathParts.Length > 5)
9577
{
96-
byte[] publicKeyToken = f.AssemblyName.GetPublicKeyToken();
97-
string publicKeyTokenHex;
98-
99-
if (publicKeyToken != null)
100-
{
101-
publicKeyTokenHex = BitConverter.ToString(publicKeyToken)
102-
.ToLowerInvariant()
103-
.Replace("-", "");
104-
}
105-
else
106-
{
107-
Log.LogError($"No public key token found for assembly {f.Item.ItemSpec}");
108-
publicKeyTokenHex = "";
109-
}
110-
111-
element.Add(
112-
new XAttribute("AssemblyName", f.AssemblyName.Name),
113-
new XAttribute("PublicKeyToken", publicKeyTokenHex),
114-
new XAttribute("AssemblyVersion", f.AssemblyName.Version));
78+
Log.LogError($"Unexpected analyzer path format {path}. Expected 'analyzers/dotnet(/roslyn<version>)(/language)/analyzer.dll");
11579
}
116-
else if (!f.IsNative)
80+
81+
// Check if we have enough parts for language directory and include it.
82+
// There could be a roslyn<version> folder before the language folder. Check for it.
83+
bool hasRoslynVersion = pathParts[2].StartsWith("roslyn", StringComparison.Ordinal);
84+
int languageLengthCheck = hasRoslynVersion ? 4 : 3;
85+
int potentialLanguageIndex = hasRoslynVersion ? 3 : 2;
86+
if (pathParts.Length > languageLengthCheck)
11787
{
118-
// This file isn't managed and isn't native. Leave it off the list.
119-
continue;
88+
element.Add(new XAttribute("Language", pathParts[potentialLanguageIndex]));
12089
}
90+
}
91+
92+
element.Add(new XAttribute("Type", type));
93+
94+
if (f.AssemblyName != null)
95+
{
96+
byte[] publicKeyToken = f.AssemblyName.GetPublicKeyToken();
97+
string publicKeyTokenHex;
12198

122-
element.Add(new XAttribute("FileVersion", f.FileVersion));
99+
if (publicKeyToken != null)
100+
{
101+
publicKeyTokenHex = BitConverter.ToString(publicKeyToken)
102+
.ToLowerInvariant()
103+
.Replace("-", "");
104+
}
105+
else
106+
{
107+
Log.LogError($"No public key token found for assembly {f.Item.ItemSpec}");
108+
publicKeyTokenHex = "";
109+
}
123110

124-
frameworkManifest.Add(element);
111+
element.Add(
112+
new XAttribute("AssemblyName", f.AssemblyName.Name),
113+
new XAttribute("PublicKeyToken", publicKeyTokenHex),
114+
new XAttribute("AssemblyVersion", f.AssemblyName.Version));
115+
}
116+
else if (!f.IsNative)
117+
{
118+
// This file isn't managed and isn't native. Leave it off the list.
119+
continue;
125120
}
126121

127-
Directory.CreateDirectory(Path.GetDirectoryName(TargetFile));
128-
File.WriteAllText(TargetFile, frameworkManifest.ToString());
122+
element.Add(new XAttribute("FileVersion", f.FileVersion));
129123

130-
return !Log.HasLoggedErrors;
124+
frameworkManifest.Add(element);
131125
}
132-
private static string GetPackagePath(ITaskItem item)
133-
{
134-
string packagePath = item.GetMetadata("PackagePath");
135126

136-
// replicate the logic used by PackTask https://github.com/NuGet/NuGet.Client/blob/f24bad0668193ce21a1db8cabd1ce95ba509c7f0/src/NuGet.Core/NuGet.Build.Tasks.Pack/PackTaskLogic.cs#L644-L647
137-
string recursiveDir = item.GetMetadata("RecursiveDir");
138-
recursiveDir = string.IsNullOrEmpty(recursiveDir) ? item.GetMetadata("NuGetRecursiveDir") : recursiveDir;
127+
Directory.CreateDirectory(Path.GetDirectoryName(TargetFile));
128+
File.WriteAllText(TargetFile, frameworkManifest.ToString());
139129

140-
return string.IsNullOrEmpty(recursiveDir) ? packagePath :
141-
Path.Combine(packagePath, recursiveDir);
142-
}
130+
return !Log.HasLoggedErrors;
143131
}
132+
private static string GetPackagePath(ITaskItem item)
133+
{
134+
string packagePath = item.GetMetadata("PackagePath");
135+
136+
// replicate the logic used by PackTask https://github.com/NuGet/NuGet.Client/blob/f24bad0668193ce21a1db8cabd1ce95ba509c7f0/src/NuGet.Core/NuGet.Build.Tasks.Pack/PackTaskLogic.cs#L644-L647
137+
string recursiveDir = item.GetMetadata("RecursiveDir");
138+
recursiveDir = string.IsNullOrEmpty(recursiveDir) ? item.GetMetadata("NuGetRecursiveDir") : recursiveDir;
144139

140+
return string.IsNullOrEmpty(recursiveDir) ? packagePath :
141+
Path.Combine(packagePath, recursiveDir);
142+
}
145143
}

0 commit comments

Comments
 (0)