Skip to content

Commit 7a7f2d3

Browse files
committed
documentation
1 parent 821e5b3 commit 7a7f2d3

6 files changed

Lines changed: 112 additions & 15 deletions

File tree

src/PetroglyphTools/PG.StarWarsGame.Engine.FileSystem.Test/IO/PetroglyphFileSystemTests.Exist.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public void FileExists_CaseInsensitive_DotSegmentInPath_ReturnsTrue()
166166
// Input path uses a leading ".\" (dot-segment) AND different casing.
167167
// After normalization + join: tempDir/./DATA/file.txt
168168
// File.Exists fast-path fails (case mismatch), so the impl must resolve case-insensitively.
169-
// Correct impls must handle "." as a valid path segment that resolves to the current directory,
169+
// Correct implementations must handle "." as a valid path segment that resolves to the current directory,
170170
// not treat it as a literal directory name to look up via GetDirectories.
171171
var vsb = new ValueStringBuilder();
172172
var exists = _pgFileSystem.FileExists(@".\DATA\file.txt".AsSpan(), ref vsb, tempDir.AsSpan());
@@ -215,11 +215,9 @@ public void FileExists_CaseInsensitive_MissingIntermediateDirectory_ReturnsFalse
215215
[InlineData("test.txt", false)]
216216
public void IsPathFullyQualified_Exists_Internal(string path, bool expected)
217217
{
218-
// This method is internal/private, but we can indirectly test it through FileExists or use reflection if we want to be explicit.
219-
// Actually, FileExists calls it.
220-
// If it's fully qualified, it doesn't join with gameDirectory.
221-
222-
var gameDir = "Z:\\non-existent-dir";
218+
// This method is internal/private, but we can indirectly test it through FileExists
219+
220+
const string gameDir = "Z:\\non-existent-dir";
223221
var vsb = new ValueStringBuilder();
224222
_pgFileSystem.FileExists(path.AsSpan(), ref vsb, gameDir.AsSpan());
225223

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ namespace PG.StarWarsGame.Engine.IO;
1313

1414
public sealed partial class PetroglyphFileSystem
1515
{
16-
internal bool FileExists(
17-
ReadOnlySpan<char> filePath,
18-
ref ValueStringBuilder stringBuilder,
19-
ReadOnlySpan<char> gameDirectory)
16+
internal bool FileExists(ReadOnlySpan<char> filePath, ref ValueStringBuilder stringBuilder, ReadOnlySpan<char> gameDirectory)
2017
{
2118
stringBuilder.Length = 0;
2219

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

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,18 @@ namespace PG.StarWarsGame.Engine.IO;
99

1010
public sealed partial class PetroglyphFileSystem
1111
{
12-
12+
13+
/// <summary>
14+
/// The path string from which to obtain the file name and extension.
15+
/// </summary>
16+
/// <param name="path"></param>
17+
/// <returns>The characters after the last directory separator character in <paramref name="path"/>.
18+
/// If the last character of <paramref name="path"/> is a directory or volume separator character, this method returns Empty.
19+
/// If <paramref name="path"/> is <see langword="null"/>, this method returns <see langword="null"/>.</returns>
20+
/// <remarks>
21+
/// The returned value is <see langword="null"/> if the file path is <see langword="null"/>.
22+
/// The separator characters used to determine the start of the file name are ("/") and ("\").
23+
/// </remarks>
1324
#if NETSTANDARD2_1 || NET
1425
[return: NotNullIfNotNull(nameof(path))]
1526
#endif
@@ -26,6 +37,16 @@ public sealed partial class PetroglyphFileSystem
2637
return result.ToString();
2738
}
2839

40+
/// <summary>
41+
/// Returns the file name and extension of a file path that is represented by a read-only character span.
42+
/// </summary>
43+
/// <param name="path">A read-only span that contains the path from which to obtain the file name and extension.</param>
44+
/// <returns>The characters after the last directory separator character in <paramref name="path"/>.</returns>
45+
/// <remarks>
46+
/// The returned read-only span contains the characters of the path that follow the last separator in path.
47+
/// If the last character in path is a volume or directory separator character, the method returns <see cref="ReadOnlySpan{T}.Empty"/>.
48+
/// If path contains no separator character, the method returns path.
49+
/// </remarks>
2950
public ReadOnlySpan<char> GetFileName(ReadOnlySpan<char> path)
3051
{
3152
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
@@ -36,6 +57,11 @@ public ReadOnlySpan<char> GetFileName(ReadOnlySpan<char> path)
3657
return path.Slice(i < root ? root : i + 1);
3758
}
3859

60+
/// <summary>
61+
/// Returns the file name of the specified path string without the extension.
62+
/// </summary>
63+
/// <param name="path">The path of the file.</param>
64+
/// <returns>The string returned by <see cref="GetFileName(ReadOnlySpan{char})"/>, minus the last period (.) and all characters following it.</returns>
3965
#if NETSTANDARD2_1 || NET
4066
[return: NotNullIfNotNull(nameof(path))]
4167
#endif
@@ -53,6 +79,11 @@ public ReadOnlySpan<char> GetFileName(ReadOnlySpan<char> path)
5379
: result.ToString();
5480
}
5581

82+
/// <summary>
83+
/// Returns the file name without the extension of a file path that is represented by a read-only character span.
84+
/// </summary>
85+
/// <param name="path">A read-only span that contains the path from which to obtain the file name without the extension.</param>
86+
/// <returns>The characters in the read-only span returned by <see cref="GetFileName(ReadOnlySpan{char})"/>, minus the last period (.) and all characters following it.</returns>
5687
public ReadOnlySpan<char> GetFileNameWithoutExtension(ReadOnlySpan<char> path)
5788
{
5889
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
@@ -65,6 +96,49 @@ public ReadOnlySpan<char> GetFileNameWithoutExtension(ReadOnlySpan<char> path)
6596
fileName.Slice(0, lastPeriod);
6697
}
6798

99+
/// <summary>
100+
/// Changes the extension of a path string.
101+
/// </summary>
102+
/// <param name="path">The path information to modify.</param>
103+
/// <param name="extension">The new extension (with or without a leading period). Specify <see langword="null"/> to remove an existing extension from <paramref name="path"/>.</param>
104+
/// <returns>
105+
/// The modified path information.
106+
/// <para>
107+
/// If <paramref name="path"/> is <see langword="null"/> or an empty string (""), the path information is returned unmodified.
108+
/// If <paramref name="extension"/> is <see langword="null"/>, the returned string contains the specified path with its extension removed.
109+
/// If <paramref name="path"/> has no extension, and <paramref name="extension"/> is not <see langword="null"/>,
110+
/// the returned path string contains <paramref name="extension"/> appended to the end of <paramref name="path"/>.
111+
/// </para>
112+
/// </returns>
113+
/// <remarks>
114+
/// <para>
115+
/// If neither <paramref name="path"/> nor <paramref name="extension"/> contains a period (.), ChangeExtension adds the period.
116+
/// </para>
117+
/// <para>
118+
/// The <paramref name="extension"/> parameter can contain multiple periods and any valid path characters, and can be any length. If <paramref name="extension"/> is <see langword="null"/> ,
119+
/// the returned string contains the contents of <paramref name="path"/> with the last period and all characters following it removed.
120+
/// </para>
121+
/// <para>
122+
/// If <paramref name="extension"/> is an empty string, the returned path string contains the contents of <paramref name="path"/> with any characters following the last period removed.
123+
/// </para>
124+
/// <para>
125+
/// If <paramref name="path"/> does not have an extension and <paramref name="extension"/> is not <see langword="null"/>,
126+
/// the returned string contains <paramref name="path"/> followed by <paramref name="extension"/>.
127+
/// </para>
128+
/// <para>
129+
/// If <paramref name="extension"/> is not <see langword="null"/> and does not contain a leading period, the period is added.
130+
/// </para>
131+
/// <para>
132+
/// If <paramref name="path"/> contains a multiple extension separated by multiple periods,
133+
/// the returned string contains the contents of <paramref name="path"/> with the last period and all characters following it replaced by <paramref name="extension"/>.
134+
/// For example, if <paramref name="path"/> is <c>"\Dir1\examples\pathtests.csx.txt"</c> and <paramref name="extension"/> is <c>"cs"</c>,
135+
/// the modified path is <c>"\Dir1\examples\pathtests.csx.cs"</c>.
136+
/// </para>
137+
/// <para>
138+
/// It is not possible to verify that the returned results are valid in all scenarios. For example,
139+
/// if <paramref name="path"/> is empty, <paramref name="extension"/> is appended.
140+
/// </para>
141+
/// </remarks>
68142
#if NETSTANDARD2_1 || NET
69143
[return: NotNullIfNotNull(nameof(path))]
70144
#endif
@@ -109,7 +183,13 @@ public ReadOnlySpan<char> GetFileNameWithoutExtension(ReadOnlySpan<char> path)
109183
return string.Concat(subPath, ".", extension);
110184
#endif
111185
}
112-
186+
187+
/// <summary>
188+
/// Returns the directory information for the specified path represented by a character span.
189+
/// </summary>
190+
/// <param name="path">The path to retrieve the directory information from.</param>
191+
/// <returns>Directory information for <paramref name="path"/>, or an empty span if <paramref name="path"/> is <see langword="null"/>,
192+
/// an empty span, or a root (such as \, C:, or \server\share).</returns>
113193
public ReadOnlySpan<char> GetDirectoryName(ReadOnlySpan<char> path)
114194
{
115195
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ namespace PG.StarWarsGame.Engine.IO;
77

88
public sealed partial class PetroglyphFileSystem
99
{
10-
10+
/// <summary>
11+
/// Determines whether two file system paths are considered equal.
12+
/// </summary>
13+
/// <param name="pathA">The first path to compare.</param>
14+
/// <param name="pathB">The second path to compare.</param>
15+
/// <returns>
16+
/// <see langword="true"/> if the paths are considered equal; otherwise, <see langword="false"/>.
17+
/// </returns>
1118
public bool PathsAreEqual(string pathA, string pathB)
1219
{
1320
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,28 @@ public sealed partial class PetroglyphFileSystem
3434
/// </summary>
3535
public IFileSystem UnderlyingFileSystem => _underlyingFileSystem;
3636

37+
/// <summary>
38+
/// Initializes a new instance of the <see cref="PetroglyphFileSystem"/> class.
39+
/// </summary>
40+
/// <param name="serviceProvider">The <see cref="IServiceProvider"/> used to resolve dependencies required by the file system.</param>
41+
/// <exception cref="ArgumentNullException"><paramref name="serviceProvider"/> is <see langword="null"/>.</exception>
3742
public PetroglyphFileSystem(IServiceProvider serviceProvider)
3843
{
3944
if (serviceProvider == null)
4045
throw new ArgumentNullException(nameof(serviceProvider));
4146
_underlyingFileSystem = serviceProvider.GetRequiredService<IFileSystem>();
4247
}
4348

49+
/// <summary>
50+
/// Determines whether the specified path ends with a directory separator character.
51+
/// </summary>
52+
/// <param name="path">The path to check for a trailing directory separator.</param>
53+
/// <returns>
54+
/// <see langword="true"/> if the path ends with a directory separator character; otherwise, <see langword="false"/>.
55+
/// </returns>
56+
/// <remarks>
57+
/// This method always considers both <c>'/'</c> and <c>'\\'</c> as valid directory separator characters.
58+
/// </remarks>
4459
public bool HasTrailingDirectorySeparator(ReadOnlySpan<char> path)
4560
{
4661
return path.Length > 0 && IsDirectorySeparator(path[path.Length - 1]);

src/PetroglyphTools/PG.StarWarsGame.Engine.FileSystem/PG.StarWarsGame.Engine.FileSystem.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
<PackageTags>alamo,petroglyph,glyphx</PackageTags>
99
</PropertyGroup>
1010
<PropertyGroup>
11-
<!--<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
11+
<!--<TreatWarningsAsErrors>true</TreatWarningsAsErrors>-->
1212
<GenerateDocumentationFile>true</GenerateDocumentationFile>
13-
<InheritDocEnabled>true</InheritDocEnabled>-->
13+
<InheritDocEnabled>true</InheritDocEnabled>
1414
</PropertyGroup>
1515
<PropertyGroup>
1616
<IncludeSymbols>true</IncludeSymbols>

0 commit comments

Comments
 (0)