Skip to content

Commit 11a40fa

Browse files
committed
move to auto-property
1 parent c83c363 commit 11a40fa

6 files changed

Lines changed: 35 additions & 33 deletions

File tree

src/PetroglyphTools/PG.StarWarsGame.Engine.FileSystem/IO/PetroglyphFileSystem.CombineJoin.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public sealed partial class PetroglyphFileSystem
3030
public string CombinePath(string pathA, string pathB)
3131
{
3232
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
33-
return _underlyingFileSystem.Path.Combine(pathA, pathB);
33+
return UnderlyingFileSystem.Path.Combine(pathA, pathB);
3434

3535
if (pathA == null)
3636
throw new ArgumentNullException(nameof(pathA));
@@ -55,7 +55,7 @@ internal void JoinPath(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2, ref V
5555

5656
var hasSeparator = IsDirectorySeparator(path1[path1.Length - 1]) || IsDirectorySeparator(path2[0]);
5757
if (!hasSeparator)
58-
stringBuilder.Append(_underlyingFileSystem.Path.DirectorySeparatorChar);
58+
stringBuilder.Append(UnderlyingFileSystem.Path.DirectorySeparatorChar);
5959

6060
stringBuilder.Append(path2);
6161
}
@@ -79,6 +79,6 @@ private string JoinInternal(string first, string second)
7979
var hasSeparator = IsDirectorySeparator(first[first.Length - 1]) || IsDirectorySeparator(second[0]);
8080
return hasSeparator
8181
? string.Concat(first, second)
82-
: string.Concat(first, _underlyingFileSystem.Path.DirectorySeparatorChar, second);
82+
: string.Concat(first, UnderlyingFileSystem.Path.DirectorySeparatorChar, second);
8383
}
8484
}

src/PetroglyphTools/PG.StarWarsGame.Engine.FileSystem/IO/PetroglyphFileSystem.Exist.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ internal bool FileExists(ReadOnlySpan<char> filePath, ref ValueStringBuilder str
4545
NormalizePath(ref stringBuilder);
4646
NormalizeDotSegmentsInPlace(ref stringBuilder);
4747

48-
return _strategy.FileExists(baseDirectory, ref stringBuilder);
48+
return Strategy.FileExists(baseDirectory, ref stringBuilder);
4949
}
5050

5151
internal void NormalizeDotSegmentsInPlace(ref ValueStringBuilder sb)
@@ -54,7 +54,7 @@ internal void NormalizeDotSegmentsInPlace(ref ValueStringBuilder sb)
5454
if (len == 0)
5555
return;
5656

57-
var dirSeparator = _underlyingFileSystem.Path.DirectorySeparatorChar;
57+
var dirSeparator = UnderlyingFileSystem.Path.DirectorySeparatorChar;
5858

5959
var rootLen = GetPathRoot(sb.AsSpan()).Length;
6060
var writeEnd = rootLen;
@@ -106,6 +106,6 @@ internal bool IsPathFullyQualified_Exists(ReadOnlySpan<char> path)
106106
// However, this must not happen here, since we are operating on the actual file system.
107107
// E.g, \\Data\\Art\\... MUST not be treated as a fully qualified path.
108108
// This means, ultimately, we can just delegate to the underlying file system.
109-
return _underlyingFileSystem.Path.IsPathFullyQualified(path);
109+
return UnderlyingFileSystem.Path.IsPathFullyQualified(path);
110110
}
111111
}

src/PetroglyphTools/PG.StarWarsGame.Engine.FileSystem/IO/PetroglyphFileSystem.Names.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public sealed partial class PetroglyphFileSystem
2828
public string? GetFileName(string? path)
2929
{
3030
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
31-
return _underlyingFileSystem.Path.GetFileName(path);
31+
return UnderlyingFileSystem.Path.GetFileName(path);
3232

3333
if (path == null)
3434
return null;
@@ -51,7 +51,7 @@ public sealed partial class PetroglyphFileSystem
5151
public ReadOnlySpan<char> GetFileName(ReadOnlySpan<char> path)
5252
{
5353
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
54-
return _underlyingFileSystem.Path.GetFileName(path);
54+
return UnderlyingFileSystem.Path.GetFileName(path);
5555

5656
var root = GetPathRoot(path).Length;
5757
var i = path.LastIndexOfAny(DirectorySeparatorChar, AltDirectorySeparatorChar);
@@ -69,7 +69,7 @@ public ReadOnlySpan<char> GetFileName(ReadOnlySpan<char> path)
6969
public string? GetFileNameWithoutExtension(string? path)
7070
{
7171
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
72-
return _underlyingFileSystem.Path.GetFileNameWithoutExtension(path);
72+
return UnderlyingFileSystem.Path.GetFileNameWithoutExtension(path);
7373

7474
if (path == null)
7575
return null;
@@ -88,7 +88,7 @@ public ReadOnlySpan<char> GetFileName(ReadOnlySpan<char> path)
8888
public ReadOnlySpan<char> GetFileNameWithoutExtension(ReadOnlySpan<char> path)
8989
{
9090
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
91-
return _underlyingFileSystem.Path.GetFileNameWithoutExtension(path);
91+
return UnderlyingFileSystem.Path.GetFileNameWithoutExtension(path);
9292
var fileName = GetFileName(path);
9393
var lastPeriod = fileName.LastIndexOf('.');
9494
return lastPeriod < 0
@@ -146,7 +146,7 @@ public ReadOnlySpan<char> GetFileNameWithoutExtension(ReadOnlySpan<char> path)
146146
public string? ChangeExtension(string? path, string? extension)
147147
{
148148
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
149-
return _underlyingFileSystem.Path.ChangeExtension(path, extension);
149+
return UnderlyingFileSystem.Path.ChangeExtension(path, extension);
150150

151151
if (path == null)
152152
return null;
@@ -194,7 +194,7 @@ public ReadOnlySpan<char> GetFileNameWithoutExtension(ReadOnlySpan<char> path)
194194
public ReadOnlySpan<char> GetDirectoryName(ReadOnlySpan<char> path)
195195
{
196196
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
197-
return _underlyingFileSystem.Path.GetDirectoryName(path);
197+
return UnderlyingFileSystem.Path.GetDirectoryName(path);
198198

199199
if (IsEffectivelyEmpty(path))
200200
return ReadOnlySpan<char>.Empty;

src/PetroglyphTools/PG.StarWarsGame.Engine.FileSystem/IO/PetroglyphFileSystem.PathEqual.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ public sealed partial class PetroglyphFileSystem
1818
public bool PathsAreEqual(string pathA, string pathB)
1919
{
2020
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
21-
return _underlyingFileSystem.Path.AreEqual(pathA, pathB);
21+
return UnderlyingFileSystem.Path.AreEqual(pathA, pathB);
2222

2323
var normalizedA = PathNormalizer.Normalize(pathA, PGFileSystemDirectorySeparatorNormalizeOptions);
2424
var normalizedB = PathNormalizer.Normalize(pathB, PGFileSystemDirectorySeparatorNormalizeOptions);
2525

26-
var fullA = _underlyingFileSystem.Path.GetFullPath(normalizedA);
27-
var fullB = _underlyingFileSystem.Path.GetFullPath(normalizedB);
26+
var fullA = UnderlyingFileSystem.Path.GetFullPath(normalizedA);
27+
var fullB = UnderlyingFileSystem.Path.GetFullPath(normalizedB);
2828

2929
return PathsEqual(fullA.AsSpan(), fullB.AsSpan(), Math.Max(fullA.Length, fullB.Length));
3030
}

src/PetroglyphTools/PG.StarWarsGame.Engine.FileSystem/IO/PetroglyphFileSystem.Strategies.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
using System;
2+
using System.ComponentModel;
3+
using System.Diagnostics.CodeAnalysis;
24
using System.Runtime.InteropServices;
35
using PG.StarWarsGame.Engine.IO.FileExistStrategies;
46

57
namespace PG.StarWarsGame.Engine.IO;
68

79
public sealed partial class PetroglyphFileSystem
810
{
9-
private FileExistsStrategy _strategy;
11+
[ExcludeFromCodeCoverage]
12+
[EditorBrowsable(EditorBrowsableState.Never)]
13+
internal FileExistsStrategy Strategy { get; private set; }
1014

11-
internal void CleanupStrategy() => _strategy.Cleanup();
15+
internal void CleanupStrategy() => Strategy.Cleanup();
1216

1317
private FileExistsStrategy CreateDefaultStrategy()
1418
{
1519
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
16-
? new WindowsFileExistsStrategy(_underlyingFileSystem)
17-
: new VirtualFileExistsStrategy(_underlyingFileSystem, new WineFileExistsStrategy(_underlyingFileSystem));
20+
? new WindowsFileExistsStrategy(UnderlyingFileSystem)
21+
: new VirtualFileExistsStrategy(UnderlyingFileSystem, new WineFileExistsStrategy(UnderlyingFileSystem));
1822
}
1923

2024
/// <summary>
@@ -38,7 +42,7 @@ private FileExistsStrategy CreateDefaultStrategy()
3842
/// </note>
3943
/// <para>Provides full mediation: every lookup re-walks the path with no caching.</para>
4044
/// </remarks>
41-
public void UseWineStrategy() => SwapStrategy(new WineFileExistsStrategy(_underlyingFileSystem));
45+
public void UseWineStrategy() => SwapStrategy(new WineFileExistsStrategy(UnderlyingFileSystem));
4246

4347
/// <summary>
4448
/// Switches the active file-exists strategy to an immutable per-directory snapshot scoped to the game directory.
@@ -61,12 +65,12 @@ public void UseVirtualStrategy(bool? windowsFallback = null)
6165
var useWindows = windowsFallback ?? RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
6266
FileExistsStrategy fallback = useWindows
6367
? CreateWindowsStrategy()
64-
: new WineFileExistsStrategy(_underlyingFileSystem);
68+
: new WineFileExistsStrategy(UnderlyingFileSystem);
6569
UseVirtualStrategy(fallback);
6670
}
6771

6872
internal void UseVirtualStrategy(FileExistsStrategy underlying)
69-
=> SwapStrategy(new VirtualFileExistsStrategy(_underlyingFileSystem, underlying));
73+
=> SwapStrategy(new VirtualFileExistsStrategy(UnderlyingFileSystem, underlying));
7074

7175
/// <summary>
7276
/// Switches the active file-exists strategy to a snapshot-based one that refreshes itself when
@@ -106,25 +110,25 @@ public void UseLiveVirtualStrategy(bool? windowsFallback = null)
106110
var useWindows = windowsFallback ?? RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
107111
FileExistsStrategy fallback = useWindows
108112
? CreateWindowsStrategy()
109-
: new WineFileExistsStrategy(_underlyingFileSystem);
113+
: new WineFileExistsStrategy(UnderlyingFileSystem);
110114
UseLiveVirtualStrategy(fallback);
111115
}
112116

113117
internal void UseLiveVirtualStrategy(FileExistsStrategy underlying)
114-
=> SwapStrategy(new LiveVirtualFileExistsStrategy(_underlyingFileSystem, underlying));
118+
=> SwapStrategy(new LiveVirtualFileExistsStrategy(UnderlyingFileSystem, underlying));
115119

116120
private WindowsFileExistsStrategy CreateWindowsStrategy()
117121
{
118122
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
119123
throw new PlatformNotSupportedException(
120124
"The Windows file-exists strategy relies on Win32 CreateFileA and is only supported on Windows hosts.");
121-
return new WindowsFileExistsStrategy(_underlyingFileSystem);
125+
return new WindowsFileExistsStrategy(UnderlyingFileSystem);
122126
}
123127

124128
private void SwapStrategy(FileExistsStrategy next)
125129
{
126-
var old = _strategy;
127-
_strategy = next;
130+
var old = Strategy;
131+
Strategy = next;
128132
old.Cleanup();
129133
}
130134
}

src/PetroglyphTools/PG.StarWarsGame.Engine.FileSystem/IO/PetroglyphFileSystem.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ public sealed partial class PetroglyphFileSystem
2727
UnifySeparatorKind = DirectorySeparatorKind.System
2828
};
2929

30-
private readonly IFileSystem _underlyingFileSystem;
31-
3230
/// <summary>
3331
/// Gets the underlying file system abstraction.
3432
/// </summary>
35-
public IFileSystem UnderlyingFileSystem => _underlyingFileSystem;
33+
public IFileSystem UnderlyingFileSystem { get; }
3634

3735
/// <summary>
3836
/// Initializes a new instance of the <see cref="PetroglyphFileSystem"/> class.
@@ -43,9 +41,9 @@ public PetroglyphFileSystem(IServiceProvider serviceProvider)
4341
{
4442
if (serviceProvider == null)
4543
throw new ArgumentNullException(nameof(serviceProvider));
46-
_underlyingFileSystem = serviceProvider.GetRequiredService<IFileSystem>();
44+
UnderlyingFileSystem = serviceProvider.GetRequiredService<IFileSystem>();
4745

48-
_strategy = CreateDefaultStrategy();
46+
Strategy = CreateDefaultStrategy();
4947
}
5048

5149
/// <summary>
@@ -65,7 +63,7 @@ public bool HasTrailingDirectorySeparator(ReadOnlySpan<char> path)
6563

6664
internal FileSystemStream OpenRead(string filePath)
6765
{
68-
return _underlyingFileSystem.FileStream.New(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
66+
return UnderlyingFileSystem.FileStream.New(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
6967
}
7068

7169
private static bool IsPathRooted(ReadOnlySpan<char> path)

0 commit comments

Comments
 (0)