Skip to content

Commit 4952683

Browse files
committed
switch to use file-scoped namespaces
1 parent 84941d2 commit 4952683

File tree

434 files changed

+23482
-23914
lines changed

Some content is hidden

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

434 files changed

+23482
-23914
lines changed

.editorconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false:s
164164
csharp_style_allow_embedded_statements_on_same_line_experimental = false:warning
165165

166166
csharp_style_prefer_top_level_statements = true:silent
167+
csharp_style_namespace_declarations = file_scoped:error
167168

168169
#### C# Formatting Rules ####
169170

@@ -398,7 +399,7 @@ dotnet_diagnostic.IDE0110.severity = suggestion
398399
dotnet_diagnostic.IDE0120.severity = suggestion
399400
dotnet_diagnostic.IDE0130.severity = silent
400401
dotnet_diagnostic.IDE0150.severity = suggestion
401-
dotnet_diagnostic.IDE0160.severity = suggestion
402+
dotnet_diagnostic.IDE0160.severity = error
402403
dotnet_diagnostic.IDE0161.severity = silent
403404
dotnet_diagnostic.IDE0170.severity = suggestion
404405
dotnet_diagnostic.IDE0180.severity = suggestion

Common/DateOnlyExtensions.cs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
1-
namespace Common
1+
namespace Common;
2+
3+
public static class DateOnlyExtensions
24
{
3-
public static class DateOnlyExtensions
5+
extension(DateOnly)
46
{
5-
extension(DateOnly)
6-
{
7-
public static DateOnly Today
8-
=> DateOnly.FromDateTimeOffset(DateTimeOffset.UtcNow);
9-
10-
public static DateOnly FromDateTimeOffset(DateTimeOffset dateTimeOffset)
11-
=> DateOnly.FromDateTime(dateTimeOffset.DateTime);
12-
}
7+
public static DateOnly Today
8+
=> DateOnly.FromDateTimeOffset(DateTimeOffset.UtcNow);
139

14-
extension(DateOnly dateOnly)
15-
{
16-
public DateTimeOffset ToDateTimeOffset()
17-
=> new(dateOnly.Year, dateOnly.Month, dateOnly.Day, 0, 0, 0, TimeSpan.Zero);
18-
}
10+
public static DateOnly FromDateTimeOffset(DateTimeOffset dateTimeOffset)
11+
=> DateOnly.FromDateTime(dateTimeOffset.DateTime);
1912
}
2013

21-
// dummy helper class to get VS to detect the static property above
22-
// can remove this in VS 2022 17.16
23-
//public static class Foo
24-
//{
25-
// public static DateOnly Get() => DateOnly.Now;
26-
//}
14+
extension(DateOnly dateOnly)
15+
{
16+
public DateTimeOffset ToDateTimeOffset()
17+
=> new(dateOnly.Year, dateOnly.Month, dateOnly.Day, 0, 0, 0, TimeSpan.Zero);
18+
}
2719
}
20+
21+
// dummy helper class to get VS to detect the static property above
22+
// can remove this in VS 2022 17.16
23+
//public static class Foo
24+
//{
25+
// public static DateOnly Get() => DateOnly.Now;
26+
//}

Common/IEnumerableExtensions.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
namespace Common
1+
namespace Common;
2+
3+
public static class IEnumerableExtensions
24
{
3-
public static class IEnumerableExtensions
5+
public static IEnumerable<T> Fill<T>(this IEnumerable<T> source, int minLength, T fillValue)
46
{
5-
public static IEnumerable<T> Fill<T>(this IEnumerable<T> source, int minLength, T fillValue)
7+
var i = 0;
8+
foreach (var item in source)
69
{
7-
var i = 0;
8-
foreach (var item in source)
9-
{
10-
i++;
11-
yield return item;
12-
}
10+
i++;
11+
yield return item;
12+
}
1313

14-
while (i < minLength)
15-
{
16-
i++;
17-
yield return fillValue;
18-
}
14+
while (i < minLength)
15+
{
16+
i++;
17+
yield return fillValue;
1918
}
2019
}
2120
}

Common/JsonFile.cs

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,44 @@
11
using System.Text.Json;
22
using System.Text.Json.Serialization;
33

4-
namespace Common.Json
4+
namespace Common.Json;
5+
6+
public static class JsonFile
57
{
6-
public static class JsonFile
7-
{
8-
const int BufferSize = 4096;
8+
const int BufferSize = 4096;
99

10-
[JsonIgnore]
11-
public static JsonSerializerOptions DefaultSerializerOptions { get; } = new()
12-
{
13-
WriteIndented = true,
14-
AllowTrailingCommas = true
15-
};
10+
[JsonIgnore]
11+
public static JsonSerializerOptions DefaultSerializerOptions { get; } = new()
12+
{
13+
WriteIndented = true,
14+
AllowTrailingCommas = true
15+
};
1616

17-
public static async Task SerializeToFileAsync<T>(T obj, string filePath, JsonSerializerOptions? options = null)
17+
public static async Task SerializeToFileAsync<T>(T obj, string filePath, JsonSerializerOptions? options = null)
18+
{
19+
await using (var fileStream = new FileStream(
20+
filePath,
21+
FileMode.Create,
22+
FileAccess.Write,
23+
FileShare.None,
24+
bufferSize: BufferSize,
25+
useAsync: true))
1826
{
19-
await using (var fileStream = new FileStream(
20-
filePath,
21-
FileMode.Create,
22-
FileAccess.Write,
23-
FileShare.None,
24-
bufferSize: BufferSize,
25-
useAsync: true))
26-
{
27-
await JsonSerializer.SerializeAsync(fileStream, obj, options ?? DefaultSerializerOptions).ConfigureAwait(false);
28-
}
27+
await JsonSerializer.SerializeAsync(fileStream, obj, options ?? DefaultSerializerOptions).ConfigureAwait(false);
2928
}
29+
}
3030

31-
public static async Task<T?> DeserializeFromFileAsync<T>(string filePath, JsonSerializerOptions? options = null)
31+
public static async Task<T?> DeserializeFromFileAsync<T>(string filePath, JsonSerializerOptions? options = null)
32+
{
33+
await using (var fileStream = new FileStream(
34+
filePath,
35+
FileMode.Open,
36+
FileAccess.Read,
37+
FileShare.Read,
38+
bufferSize: BufferSize,
39+
useAsync: true))
3240
{
33-
await using (var fileStream = new FileStream(
34-
filePath,
35-
FileMode.Open,
36-
FileAccess.Read,
37-
FileShare.Read,
38-
bufferSize: BufferSize,
39-
useAsync: true))
40-
{
41-
return await JsonSerializer.DeserializeAsync<T?>(fileStream, options ?? DefaultSerializerOptions).ConfigureAwait(false);
42-
}
41+
return await JsonSerializer.DeserializeAsync<T?>(fileStream, options ?? DefaultSerializerOptions).ConfigureAwait(false);
4342
}
4443
}
4544
}

Common/Logging/ILogger.cs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
using System.Runtime.CompilerServices;
22

3-
namespace Common.Logging
3+
namespace Common.Logging;
4+
5+
public interface ILogger
46
{
5-
public interface ILogger
6-
{
7-
public event EventHandler<LogAddedEventArgs>? LogAdded;
7+
public event EventHandler<LogAddedEventArgs>? LogAdded;
88

9-
void Log(LogLevel level, string message, string callerMemberName, string sourceFilePath, int sourceLineNumber);
9+
void Log(LogLevel level, string message, string callerMemberName, string sourceFilePath, int sourceLineNumber);
1010

11-
void Debug2(string message, [CallerMemberName] string callerMemberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
12-
=> Log(LogLevel.Debug2, message, callerMemberName, sourceFilePath, sourceLineNumber);
11+
void Debug2(string message, [CallerMemberName] string callerMemberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
12+
=> Log(LogLevel.Debug2, message, callerMemberName, sourceFilePath, sourceLineNumber);
1313

14-
void Debug(string message, [CallerMemberName] string callerMemberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
15-
=> Log(LogLevel.Debug, message, callerMemberName, sourceFilePath, sourceLineNumber);
14+
void Debug(string message, [CallerMemberName] string callerMemberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
15+
=> Log(LogLevel.Debug, message, callerMemberName, sourceFilePath, sourceLineNumber);
1616

17-
void Info(string message, [CallerMemberName] string callerMemberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
18-
=> Log(LogLevel.Info, message, callerMemberName, sourceFilePath, sourceLineNumber);
17+
void Info(string message, [CallerMemberName] string callerMemberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
18+
=> Log(LogLevel.Info, message, callerMemberName, sourceFilePath, sourceLineNumber);
1919

20-
void Warning(string message, [CallerMemberName] string callerMemberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
21-
=> Log(LogLevel.Warning, message, callerMemberName, sourceFilePath, sourceLineNumber);
20+
void Warning(string message, [CallerMemberName] string callerMemberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
21+
=> Log(LogLevel.Warning, message, callerMemberName, sourceFilePath, sourceLineNumber);
2222

23-
void Error(string message, [CallerMemberName] string callerMemberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
24-
=> Log(LogLevel.Error, message, callerMemberName, sourceFilePath, sourceLineNumber);
23+
void Error(string message, [CallerMemberName] string callerMemberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
24+
=> Log(LogLevel.Error, message, callerMemberName, sourceFilePath, sourceLineNumber);
2525

26-
void Error(Exception ex, [CallerMemberName] string callerMemberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
27-
=> Log(LogLevel.Error, $"{ex.Message} - {ex.StackTrace}", callerMemberName, sourceFilePath, sourceLineNumber);
26+
void Error(Exception ex, [CallerMemberName] string callerMemberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
27+
=> Log(LogLevel.Error, $"{ex.Message} - {ex.StackTrace}", callerMemberName, sourceFilePath, sourceLineNumber);
2828

29-
void Error(string message, Exception ex, [CallerMemberName] string callerMemberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
30-
=> Log(LogLevel.Error, $"{message} - {ex.Message} - {ex.StackTrace}", callerMemberName, sourceFilePath, sourceLineNumber);
31-
}
29+
void Error(string message, Exception ex, [CallerMemberName] string callerMemberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
30+
=> Log(LogLevel.Error, $"{message} - {ex.Message} - {ex.StackTrace}", callerMemberName, sourceFilePath, sourceLineNumber);
3231
}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
namespace Common.Logging
1+
namespace Common.Logging;
2+
3+
public class LogAddedEventArgs(LogLine log) : EventArgs
24
{
3-
public class LogAddedEventArgs(LogLine log) : EventArgs
4-
{
5-
public readonly LogLine Log = log;
6-
}
5+
public readonly LogLine Log = log;
76
}

Common/Logging/LogLevel.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
namespace Common.Logging
2-
{
3-
public enum LogLevel { Debug2, Debug, Info, Warning, Error }
4-
}
1+
namespace Common.Logging;
2+
3+
public enum LogLevel { Debug2, Debug, Info, Warning, Error }

Common/Logging/LogLine.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
namespace Common.Logging
1+
namespace Common.Logging;
2+
3+
public record LogLine(DateTime Time, LogLevel Level, string Caller, string Message)
24
{
3-
public record LogLine(DateTime Time, LogLevel Level, string Caller, string Message)
4-
{
5-
public override string ToString()
6-
=> $"[{Time:HH:mm:ss}] [{Level}] [{Caller}] {Message}";
7-
}
5+
public override string ToString()
6+
=> $"[{Time:HH:mm:ss}] [{Level}] [{Caller}] {Message}";
87
}

Common/Logging/Logger.cs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
using System.Collections.Concurrent;
22
using System.Diagnostics;
33

4-
namespace Common.Logging
4+
namespace Common.Logging;
5+
6+
public class Logger : ILogger
57
{
6-
public class Logger : ILogger
7-
{
8-
public readonly ConcurrentQueue<LogLine> Logs = [];
9-
public LogLevel Level = LogLevel.Debug;
8+
public readonly ConcurrentQueue<LogLine> Logs = [];
9+
public LogLevel Level = LogLevel.Debug;
1010

11-
public event EventHandler<LogAddedEventArgs>? LogAdded;
11+
public event EventHandler<LogAddedEventArgs>? LogAdded;
1212

13-
public void Log(LogLevel level, string message, string callerMemberName = "", string sourceFilePath = "", int sourceLineNumber = 0)
14-
{
15-
// Get the class name using reflection
16-
var frame = new StackFrame(2); // Skip the Log methods
17-
var method = frame.GetMethod();
18-
var className = method?.DeclaringType?.Name ?? "<unknown_class>";
13+
public void Log(LogLevel level, string message, string callerMemberName = "", string sourceFilePath = "", int sourceLineNumber = 0)
14+
{
15+
// Get the class name using reflection
16+
var frame = new StackFrame(2); // Skip the Log methods
17+
var method = frame.GetMethod();
18+
var className = method?.DeclaringType?.Name ?? "<unknown_class>";
1919

20-
//var fullCaller = $"[{className}.{callerMemberName}] ({sourceFilePath}:{sourceLineNumber})";
21-
var caller = $"[{className}.{callerMemberName}]";
20+
//var fullCaller = $"[{className}.{callerMemberName}] ({sourceFilePath}:{sourceLineNumber})";
21+
var caller = $"[{className}.{callerMemberName}]";
2222

23-
var log = new LogLine(DateTime.Now, level, caller, message);
24-
Logs.Enqueue(log);
23+
var log = new LogLine(DateTime.Now, level, caller, message);
24+
Logs.Enqueue(log);
2525

26-
if (Level <= level)
27-
{
28-
LogAdded?.Invoke(this, new LogAddedEventArgs(log));
29-
}
26+
if (Level <= level)
27+
{
28+
LogAdded?.Invoke(this, new LogAddedEventArgs(log));
3029
}
3130
}
3231
}

0 commit comments

Comments
 (0)