Skip to content

Commit 2e4c5b0

Browse files
committed
Did file-scoped namespaces for the entire dotnet project. Adjusted the namespaces of source files NOT in the "commands" folder. That'll be separate.
1 parent e3a096f commit 2e4c5b0

File tree

543 files changed

+32358
-32970
lines changed

Some content is hidden

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

543 files changed

+32358
-32970
lines changed

src/Cli/dotnet/AspNetCoreCertificateGenerator.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33

44
using Microsoft.DotNet.Configurer;
55

6-
namespace Microsoft.DotNet.Cli
6+
namespace Microsoft.DotNet.Cli;
7+
8+
public class AspNetCoreCertificateGenerator : IAspNetCoreCertificateGenerator
79
{
8-
public class AspNetCoreCertificateGenerator : IAspNetCoreCertificateGenerator
10+
public void GenerateAspNetCoreDevelopmentCertificate()
911
{
10-
public void GenerateAspNetCoreDevelopmentCertificate()
11-
{
1212
#if !EXCLUDE_ASPNETCORE
13-
AspNetCore.DeveloperCertificates.XPlat.CertificateGenerator.GenerateAspNetHttpsCertificate();
13+
AspNetCore.DeveloperCertificates.XPlat.CertificateGenerator.GenerateAspNetHttpsCertificate();
1414
#endif
15-
}
1615
}
1716
}

src/Cli/dotnet/AutomaticEncodingRestorer.cs

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,58 @@
33

44
using System.Security;
55

6-
namespace Microsoft.DotNet.Cli
6+
namespace Microsoft.DotNet.Cli;
7+
8+
/// <summary>
9+
/// A program can change the encoding of the console which would affect other programs.
10+
/// We would prefer to have a pattern where the program does not affect encoding of other programs.
11+
/// Create this class in a function akin to Main and let it manage the console encoding resources to return it to the state before execution upon destruction.
12+
/// </summary>
13+
internal class AutomaticEncodingRestorer : IDisposable
714
{
8-
/// <summary>
9-
/// A program can change the encoding of the console which would affect other programs.
10-
/// We would prefer to have a pattern where the program does not affect encoding of other programs.
11-
/// Create this class in a function akin to Main and let it manage the console encoding resources to return it to the state before execution upon destruction.
12-
/// </summary>
13-
internal class AutomaticEncodingRestorer : IDisposable
14-
{
15-
Encoding _originalOutputEncoding = null;
16-
Encoding _originalInputEncoding = null;
15+
Encoding _originalOutputEncoding = null;
16+
Encoding _originalInputEncoding = null;
1717

18-
bool outputEncodingAccessible = false;
19-
bool inputEncodingAccessible = false;
18+
bool outputEncodingAccessible = false;
19+
bool inputEncodingAccessible = false;
2020

21-
public AutomaticEncodingRestorer()
21+
public AutomaticEncodingRestorer()
22+
{
23+
try
2224
{
23-
try
25+
if (!OperatingSystem.IsIOS() && !OperatingSystem.IsAndroid() && !OperatingSystem.IsTvOS()) // Output + Input Encoding are unavailable on these platforms per docs.
2426
{
25-
if (!OperatingSystem.IsIOS() && !OperatingSystem.IsAndroid() && !OperatingSystem.IsTvOS()) // Output + Input Encoding are unavailable on these platforms per docs.
27+
_originalOutputEncoding = Console.OutputEncoding;
28+
outputEncodingAccessible = true;
29+
if (!OperatingSystem.IsBrowser()) // Input Encoding is also unavailable in this platform.
2630
{
27-
_originalOutputEncoding = Console.OutputEncoding;
28-
outputEncodingAccessible = true;
29-
if (!OperatingSystem.IsBrowser()) // Input Encoding is also unavailable in this platform.
30-
{
31-
_originalInputEncoding = Console.InputEncoding;
32-
inputEncodingAccessible = true;
33-
}
31+
_originalInputEncoding = Console.InputEncoding;
32+
inputEncodingAccessible = true;
3433
}
3534
}
36-
catch (Exception ex) when (ex is IOException || ex is SecurityException)
37-
{
38-
// The encoding is unavailable. Do nothing.
39-
}
4035
}
36+
catch (Exception ex) when (ex is IOException || ex is SecurityException)
37+
{
38+
// The encoding is unavailable. Do nothing.
39+
}
40+
}
4141

42-
public void Dispose()
42+
public void Dispose()
43+
{
44+
try
4345
{
44-
try
46+
if (outputEncodingAccessible)
4547
{
46-
if (outputEncodingAccessible)
47-
{
48-
Console.OutputEncoding = _originalOutputEncoding;
49-
}
50-
if (inputEncodingAccessible)
51-
{
52-
Console.InputEncoding = _originalInputEncoding;
53-
}
48+
Console.OutputEncoding = _originalOutputEncoding;
5449
}
55-
catch (Exception ex) when (ex is IOException || ex is SecurityException)
50+
if (inputEncodingAccessible)
5651
{
57-
// The encoding is unavailable. Do nothing.
52+
Console.InputEncoding = _originalInputEncoding;
5853
}
5954
}
55+
catch (Exception ex) when (ex is IOException || ex is SecurityException)
56+
{
57+
// The encoding is unavailable. Do nothing.
58+
}
6059
}
6160
}

src/Cli/dotnet/BuildServer/RazorServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using Microsoft.DotNet.CommandFactory;
4+
using Microsoft.DotNet.Cli.CommandFactory;
55
using Microsoft.Extensions.EnvironmentAbstractions;
66

77
namespace Microsoft.DotNet.Cli.BuildServer;

src/Cli/dotnet/BuildServer/VBCSCompilerServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Reflection;
5+
using Microsoft.DotNet.Cli.CommandFactory;
56
using Microsoft.DotNet.Cli.Utils;
6-
using Microsoft.DotNet.CommandFactory;
77
using NuGet.Configuration;
88

99
namespace Microsoft.DotNet.Cli.BuildServer;

src/Cli/dotnet/BundledTargetFramework.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@
55
using System.Runtime.Versioning;
66
using NuGet.Frameworks;
77

8-
namespace Microsoft.DotNet.Cli
8+
namespace Microsoft.DotNet.Cli;
9+
10+
internal static class BundledTargetFramework
911
{
10-
internal static class BundledTargetFramework
12+
public static string GetTargetFrameworkMoniker()
1113
{
12-
public static string GetTargetFrameworkMoniker()
13-
{
14-
TargetFrameworkAttribute targetFrameworkAttribute = typeof(BundledTargetFramework)
15-
.GetTypeInfo()
16-
.Assembly
17-
.GetCustomAttribute<TargetFrameworkAttribute>();
14+
TargetFrameworkAttribute targetFrameworkAttribute = typeof(BundledTargetFramework)
15+
.GetTypeInfo()
16+
.Assembly
17+
.GetCustomAttribute<TargetFrameworkAttribute>();
1818

19-
return NuGetFramework
20-
.Parse(targetFrameworkAttribute.FrameworkName)
21-
.GetShortFolderName();
22-
}
19+
return NuGetFramework
20+
.Parse(targetFrameworkAttribute.FrameworkName)
21+
.GetShortFolderName();
2322
}
2423
}

src/Cli/dotnet/CliTransaction.cs

Lines changed: 76 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,113 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
namespace Microsoft.DotNet.Cli
4+
namespace Microsoft.DotNet.Cli;
5+
6+
internal interface ITransactionContext
57
{
6-
internal interface ITransactionContext
7-
{
8-
public void AddRollbackAction(Action action);
8+
public void AddRollbackAction(Action action);
9+
10+
// Add an action which will be run at the end of the transaction, whether it succeeds or not (after any rollback actions, if applicable)
11+
public void AddCleanupAction(Action action);
12+
}
13+
14+
internal class CliTransaction
15+
{
16+
// Delegate called when rollback starts, mainly in order to print a log message
17+
public Action RollbackStarted { get; set; }
918

10-
// Add an action which will be run at the end of the transaction, whether it succeeds or not (after any rollback actions, if applicable)
11-
public void AddCleanupAction(Action action);
19+
// Delegate called when rollback fails. If set, exception will be passed to the delegate, but not rethrown
20+
public Action<Exception> RollbackFailed { get; set; }
21+
22+
public static void RunNew(Action<ITransactionContext> action)
23+
{
24+
new CliTransaction().Run(action);
1225
}
1326

14-
internal class CliTransaction
27+
public void Run(Action<ITransactionContext> action, Action rollback)
1528
{
16-
// Delegate called when rollback starts, mainly in order to print a log message
17-
public Action RollbackStarted { get; set; }
29+
Run(context =>
30+
{
31+
context.AddRollbackAction(rollback);
1832

19-
// Delegate called when rollback fails. If set, exception will be passed to the delegate, but not rethrown
20-
public Action<Exception> RollbackFailed { get; set; }
33+
action(context);
34+
});
35+
}
2136

22-
public static void RunNew(Action<ITransactionContext> action)
37+
public void Run(Action<ITransactionContext> action)
38+
{
39+
TransactionContext transactionContext = new();
40+
try
2341
{
24-
new CliTransaction().Run(action);
42+
action(transactionContext);
2543
}
26-
27-
public void Run(Action<ITransactionContext> action, Action rollback)
44+
catch (Exception)
2845
{
29-
Run(context =>
30-
{
31-
context.AddRollbackAction(rollback);
32-
33-
action(context);
34-
});
35-
}
46+
// Roll back transaction
47+
RollbackStarted?.Invoke();
3648

37-
public void Run(Action<ITransactionContext> action)
38-
{
39-
TransactionContext transactionContext = new();
40-
try
41-
{
42-
action(transactionContext);
43-
}
44-
catch (Exception)
49+
transactionContext.RollbackActions.Reverse();
50+
foreach (var rollbackAction in transactionContext.RollbackActions)
4551
{
46-
// Roll back transaction
47-
RollbackStarted?.Invoke();
48-
49-
transactionContext.RollbackActions.Reverse();
50-
foreach (var rollbackAction in transactionContext.RollbackActions)
52+
try
53+
{
54+
rollbackAction();
55+
}
56+
catch (Exception ex)
5157
{
52-
try
58+
if (RollbackFailed != null)
5359
{
54-
rollbackAction();
60+
RollbackFailed(ex);
5561
}
56-
catch (Exception ex)
62+
else
5763
{
58-
if (RollbackFailed != null)
59-
{
60-
RollbackFailed(ex);
61-
}
62-
else
63-
{
64-
throw;
65-
}
64+
throw;
6665
}
6766
}
68-
69-
throw;
7067
}
71-
finally
68+
69+
throw;
70+
}
71+
finally
72+
{
73+
foreach (var cleanupAction in transactionContext.CleanupActions)
7274
{
73-
foreach (var cleanupAction in transactionContext.CleanupActions)
74-
{
75-
cleanupAction();
76-
}
75+
cleanupAction();
7776
}
7877
}
78+
}
7979

80-
class TransactionContext : ITransactionContext
81-
{
82-
public List<Action> RollbackActions { get; set; } = new List<Action>();
80+
class TransactionContext : ITransactionContext
81+
{
82+
public List<Action> RollbackActions { get; set; } = new List<Action>();
8383

84-
// Actions which will be run either when the transaction completes successfully, or after rollback actions have been run
85-
public List<Action> CleanupActions { get; set; } = new List<Action>();
84+
// Actions which will be run either when the transaction completes successfully, or after rollback actions have been run
85+
public List<Action> CleanupActions { get; set; } = new List<Action>();
8686

87-
public void AddRollbackAction(Action action)
88-
{
89-
RollbackActions.Add(action);
90-
}
87+
public void AddRollbackAction(Action action)
88+
{
89+
RollbackActions.Add(action);
90+
}
9191

92-
public void AddCleanupAction(Action action)
93-
{
94-
CleanupActions.Add(action);
95-
}
92+
public void AddCleanupAction(Action action)
93+
{
94+
CleanupActions.Add(action);
9695
}
9796
}
97+
}
9898

99-
static class CliTransactionExtensions
99+
static class CliTransactionExtensions
100+
{
101+
public static void Run(this ITransactionContext context, Action action, Action rollback = null, Action cleanup = null)
100102
{
101-
public static void Run(this ITransactionContext context, Action action, Action rollback = null, Action cleanup = null)
103+
if (rollback != null)
102104
{
103-
if (rollback != null)
104-
{
105-
context.AddRollbackAction(rollback);
106-
}
107-
if (cleanup != null)
108-
{
109-
context.AddCleanupAction(cleanup);
110-
}
111-
action();
105+
context.AddRollbackAction(rollback);
106+
}
107+
if (cleanup != null)
108+
{
109+
context.AddCleanupAction(cleanup);
112110
}
111+
action();
113112
}
114113
}

src/Cli/dotnet/CommandBase.cs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,22 @@
44
using System.CommandLine;
55
using Microsoft.DotNet.Cli.Extensions;
66

7-
namespace Microsoft.DotNet.Cli
8-
{
9-
public abstract class CommandBase
10-
{
11-
protected ParseResult _parseResult;
7+
namespace Microsoft.DotNet.Cli;
128

13-
protected CommandBase(ParseResult parseResult)
14-
{
15-
_parseResult = parseResult;
16-
ShowHelpOrErrorIfAppropriate(parseResult);
17-
}
9+
public abstract class CommandBase
10+
{
11+
protected ParseResult _parseResult;
1812

19-
protected virtual void ShowHelpOrErrorIfAppropriate(ParseResult parseResult)
20-
{
21-
parseResult.ShowHelpOrErrorIfAppropriate();
22-
}
13+
protected CommandBase(ParseResult parseResult)
14+
{
15+
_parseResult = parseResult;
16+
ShowHelpOrErrorIfAppropriate(parseResult);
17+
}
2318

24-
public abstract int Execute();
19+
protected virtual void ShowHelpOrErrorIfAppropriate(ParseResult parseResult)
20+
{
21+
parseResult.ShowHelpOrErrorIfAppropriate();
2522
}
23+
24+
public abstract int Execute();
2625
}

0 commit comments

Comments
 (0)