Skip to content

Commit 979ea6a

Browse files
authored
Clarify Path.GetPathRoot return value when path is effectively empty (#3233)
* Clarify Path.GetPathRoot return value when path is effectively empty * Add extra details from original issue's discussion * missed a paramref * suggestions by rpetrusha Co-Authored-By: Ron Petrusha <[email protected]> * Bring back exception, mention it is only thrown in Framework. * spacing * spacing * Update Path.xml * Update xml/System.IO/Path.xml Co-Authored-By: Maira Wenzel <[email protected]> * add missing period
1 parent 4f30eff commit 979ea6a

File tree

1 file changed

+84
-41
lines changed

1 file changed

+84
-41
lines changed

xml/System.IO/Path.xml

Lines changed: 84 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,16 +1402,42 @@ The following example defines a variable, `basePath`, to represent an applicatio
14021402
<Parameter Name="path" Type="System.ReadOnlySpan&lt;System.Char&gt;" Index="0" FrameworkAlternate="netcore-2.1;netcore-2.2;netcore-3.0;netstandard-2.1" />
14031403
</Parameters>
14041404
<Docs>
1405-
<param name="path">The path from which to obtain root directory information.</param>
1405+
<param name="path">A read-only span of characters containing the path from which to obtain root directory information.</param>
14061406
<summary>Gets the root directory information from the path contained in the specified character span.</summary>
1407-
<returns>A character span containing the root directory of `path`.</returns>
1407+
<returns>A read-only span of characters containing the root directory of <paramref name="path" />.</returns>
14081408
<remarks>
14091409
<format type="text/markdown"><![CDATA[
14101410
14111411
## Remarks
14121412
1413+
This method does not verify that the path or file exists.
1414+
14131415
Unlike the string overload, this method doesn't normalize directory separators.
14141416
1417+
A `ReadOnlySpan<System.Char>` is "effectively empty" if:
1418+
1419+
- In Windows, calling <xref:System.ReadOnlySpan%601.IsEmpty?displayProperty=nameWithType> on this span of characters returns `true`, or all its characters are spaces (' ').
1420+
- In Unix, calling <xref:System.ReadOnlySpan%601.IsEmpty?displayProperty=nameWithType> on this span of characters returns `true`.
1421+
1422+
Possible patterns for the read-only character span returned by this method are as follows:
1423+
1424+
- <xref:System.ReadOnlySpan%601.Empty?displayProperty=nameWithType> (`path` was <xref:System.ReadOnlySpan%601.Empty?displayProperty=nameWithType>.
1425+
1426+
- <xref:System.ReadOnlySpan%601.Empty?displayProperty=nameWithType> (`path` specified a relative path on the current drive or volume).
1427+
1428+
- "\" (Unix: `path` specified an absolute path on the current drive).
1429+
1430+
- "X:" (Windows: `path` specified a relative path on a drive, where *X* represents a drive or volume letter).
1431+
1432+
- "X:\" (Windows: `path` specified an absolute path on a given drive).
1433+
1434+
- "\\\ComputerName\SharedFolder" (Windows: a UNC path).
1435+
1436+
- "\\\\\?\C:" (Windows: a DOS device path, supported in .NET Core 1.1 and later versions, and in .NET Framework 4.6.2 and later versions).
1437+
1438+
For more information on file paths on Windows, see [File path formats on Windows systems](~/docs/standard/io/file-path-formats.md). For a list of common I/O tasks, see [Common I/O Tasks](~/docs/standard/io/common-i-o-tasks.md).
1439+
1440+
14151441
]]></format>
14161442
</remarks>
14171443
<related type="article" href="~/docs/standard/io/file-path-formats.md">File path formats on Windows systems</related>
@@ -1457,47 +1483,64 @@ Unlike the string overload, this method doesn't normalize directory separators.
14571483
<Parameter Name="path" Type="System.String" />
14581484
</Parameters>
14591485
<Docs>
1460-
<param name="path">The path from which to obtain root directory information.</param>
1461-
<summary>Gets the root directory information of the specified path.</summary>
1462-
<returns>The root directory of <paramref name="path" />, or <see langword="null" /> if <paramref name="path" /> is <see langword="null" />, or an empty string if <paramref name="path" /> does not contain root directory information.</returns>
1486+
<param name="path">A string containing the path from which to obtain root directory information.</param>
1487+
<summary>Gets the root directory information from the path contained in the specified string.</summary>
1488+
<returns>The root directory of <paramref name="path" /> if it is rooted.
1489+
1490+
-or-
1491+
1492+
<see cref="P:System.String.Empty" /> if <paramref name="path" /> does not contain root directory information.
1493+
1494+
-or-
1495+
1496+
<see langword="null" /> if <paramref name="path" /> is <see langword="null" /> or is effectively empty.</returns>
14631497
<remarks>
1464-
<format type="text/markdown"><![CDATA[
1465-
1466-
## Remarks
1467-
This method does not verify that the path or file name exists.
1468-
1469-
Possible patterns for the string returned by this method are as follows:
1470-
1471-
- An empty string (`path` specified a relative path on the current drive or volume).
1472-
1473-
- "\" (`path` specified an absolute path on the current drive).
1474-
1475-
- "X:" (`path` specified a relative path on a drive, where X represents a drive or volume letter).
1476-
1477-
- "X:\" (`path` specified an absolute path on a given drive).
1478-
1479-
- "\\\ComputerName\SharedFolder" (a UNC path).
1480-
1481-
- "\\\\\?\C:" (a DOS device path, supported in .NET Core 1.1 and later versions and in .NET Framework 4.6.2 and later versions)
1482-
1483-
For more information on file paths on Windows, see [File path formats on Windows systems](~/docs/standard/io/file-path-formats.md). For a list of common I/O tasks, see [Common I/O Tasks](~/docs/standard/io/common-i-o-tasks.md).
1484-
1485-
## Examples
1486-
The following example demonstrates a use of the `GetPathRoot` method.
1487-
1488-
[!code-cpp[System.IO.Path Members#8](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.IO.Path Members/CPP/pathmembers.cpp#8)]
1489-
[!code-csharp[System.IO.Path Members#8](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.IO.Path Members/CS/pathmembers.cs#8)]
1490-
[!code-vb[System.IO.Path Members#8](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.IO.Path Members/VB/pathmembers.vb#8)]
1491-
1492-
]]></format>
1498+
<format type="text/markdown"><![CDATA[
1499+
1500+
## Remarks
1501+
1502+
This method does not verify that the path or file exists.
1503+
1504+
This method will normalize directory separators.
1505+
1506+
A string is "effectively empty" if:
1507+
1508+
- In Windows, calling `IsEmpty` on this string returns `true`, or all its characters are spaces (' ').
1509+
- In Unix, calling <xref:System.String.IsNullOrEmpty%2A> on this string returns `true`.
1510+
1511+
Possible patterns for the string returned by this method are as follows:
1512+
1513+
- `null` (`path` was null or an empty string).
1514+
1515+
- An empty string (`path` specified a relative path on the current drive or volume).
1516+
1517+
- "\" (Unix: `path` specified an absolute path on the current drive).
1518+
1519+
- "X:" (Windows: `path` specified a relative path on a drive, where *X* represents a drive or volume letter).
1520+
1521+
- "X:\" (Windows: `path` specified an absolute path on a given drive).
1522+
1523+
- "\\\ComputerName\SharedFolder" (Windows: a UNC path).
1524+
1525+
- "\\\\\?\C:" (Windows: a DOS device path, supported in .NET Core 1.1 and later versions, and in .NET Framework 4.6.2 and later versions).
1526+
1527+
For more information on file paths on Windows, see [File path formats on Windows systems](~/docs/standard/io/file-path-formats.md). For a list of common I/O tasks, see [Common I/O Tasks](~/docs/standard/io/common-i-o-tasks.md).
1528+
1529+
## Examples
1530+
The following example demonstrates a use of the `GetPathRoot` method.
1531+
1532+
[!code-cpp[System.IO.Path Members#8](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.IO.Path Members/CPP/pathmembers.cpp#8)]
1533+
[!code-csharp[System.IO.Path Members#8](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.IO.Path Members/CS/pathmembers.cs#8)]
1534+
[!code-vb[System.IO.Path Members#8](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.IO.Path Members/VB/pathmembers.vb#8)]
1535+
1536+
]]></format>
14931537
</remarks>
1494-
<exception cref="T:System.ArgumentException">
1495-
<paramref name="path" /> contains one or more of the invalid characters defined in <see cref="M:System.IO.Path.GetInvalidPathChars" />.
1496-
1497-
-or-
1498-
1499-
<see cref="F:System.String.Empty" /> was passed to <paramref name="path" />.</exception>
1500-
<related type="article" href="~/docs/standard/io/file-path-formats.md">File path formats on Windows systems</related>
1538+
<exception cref="T:System.ArgumentException">.NET Framework only: <paramref name="path" /> contains one or more of the invalid characters defined in <see cref="M:System.IO.Path.GetInvalidPathChars" />.
1539+
1540+
-or-
1541+
1542+
.NET Framework only: <see cref="F:System.String.Empty" /> was passed to <paramref name="path" />.</exception>
1543+
<related type="Article" href="~/docs/standard/io/file-path-formats.md">File path formats on Windows systems</related>
15011544
<related type="Article" href="~/docs/standard/io/index.md">File and Stream I/O</related>
15021545
<related type="Article" href="~/docs/standard/io/how-to-read-text-from-a-file.md">How to: Read Text from a File</related>
15031546
<related type="Article" href="~/docs/standard/io/how-to-write-text-to-a-file.md">How to: Write Text to a File</related>

0 commit comments

Comments
 (0)