Skip to content

Commit 5978bed

Browse files
authored
Remove platform dependent compilation of System.Private.Uri (#68011)
* Use OperatingSystem.IsWindows() in Uri. * Remove platform specific files. * Remove platform specific compilation for System.Private.Uri.
1 parent 85e715a commit 5978bed

File tree

5 files changed

+8
-34
lines changed

5 files changed

+8
-34
lines changed

src/libraries/System.Private.Uri/src/System.Private.Uri.csproj

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
44
<Nullable>enable</Nullable>
5-
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)</TargetFrameworks>
5+
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
66
</PropertyGroup>
77
<ItemGroup>
88
<Compile Include="$(CommonPath)System\Collections\Generic\ArrayBuilder.cs"
@@ -37,12 +37,6 @@
3737
<Compile Include="$(CommonPath)System\Text\ValueStringBuilder.cs" Link="Common\System\Text\ValueStringBuilder.cs" />
3838
<Compile Include="System\ValueStringBuilderExtensions.cs" />
3939
</ItemGroup>
40-
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'windows'">
41-
<Compile Include="System\Uri.Windows.cs" />
42-
</ItemGroup>
43-
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == ''">
44-
<Compile Include="System\Uri.Unix.cs" />
45-
</ItemGroup>
4640
<ItemGroup>
4741
<ProjectReference Include="$(CoreLibProject)" />
4842
</ItemGroup>

src/libraries/System.Private.Uri/src/System/Uri.Unix.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/libraries/System.Private.Uri/src/System/Uri.Windows.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/libraries/System.Private.Uri/src/System/Uri.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,7 +1900,7 @@ private unsafe ParsingError PrivateParseMinimal()
19001900
}
19011901

19021902
// Unix Path
1903-
if (!IsWindowsSystem && InFact(Flags.UnixPath))
1903+
if (!OperatingSystem.IsWindows() && InFact(Flags.UnixPath))
19041904
{
19051905
_flags |= Flags.BasicHostType;
19061906
_flags |= (Flags)idx;
@@ -1974,7 +1974,7 @@ private unsafe ParsingError PrivateParseMinimal()
19741974
_flags |= Flags.UncPath;
19751975
idx = i;
19761976
}
1977-
else if (!IsWindowsSystem && _syntax.InFact(UriSyntaxFlags.FileLikeUri) && pUriString[i - 1] == '/' && i - idx == 3)
1977+
else if (!OperatingSystem.IsWindows() && _syntax.InFact(UriSyntaxFlags.FileLikeUri) && pUriString[i - 1] == '/' && i - idx == 3)
19781978
{
19791979
_syntax = UriParser.UnixFileUri;
19801980
_flags |= Flags.UnixPath | Flags.AuthorityFound;
@@ -2077,7 +2077,7 @@ private unsafe ParsingError PrivateParseMinimal()
20772077
return ParsingError.BadAuthorityTerminator;
20782078
}
20792079
// When the hostTerminator is '/' on Unix, use the UnixFile syntax (preserve backslashes)
2080-
else if (!IsWindowsSystem && hostTerminator == '/' && NotAny(Flags.ImplicitFile) && InFact(Flags.UncPath) && _syntax == UriParser.FileUri)
2080+
else if (!OperatingSystem.IsWindows() && hostTerminator == '/' && NotAny(Flags.ImplicitFile) && InFact(Flags.UncPath) && _syntax == UriParser.FileUri)
20812081
{
20822082
_syntax = UriParser.UnixFileUri;
20832083
}
@@ -3510,7 +3510,7 @@ private static unsafe int ParseSchemeCheckImplicitFile(char* uriString, int leng
35103510

35113511
// Unix: Unix path?
35123512
// A path starting with 2 / or \ (including mixed) is treated as UNC and will be matched below
3513-
if (!IsWindowsSystem && idx < length && uriString[idx] == '/' &&
3513+
if (!OperatingSystem.IsWindows() && idx < length && uriString[idx] == '/' &&
35143514
(idx + 1 == length || (uriString[idx + 1] != '/' && uriString[idx + 1] != '\\')))
35153515
{
35163516
flags |= (Flags.UnixPath | Flags.ImplicitFile | Flags.AuthorityFound);
@@ -4481,7 +4481,7 @@ private unsafe void GetCanonicalPath(ref ValueStringBuilder dest, UriFormat form
44814481
}
44824482

44834483
// On Unix, escape '\\' in path of file uris to '%5C' canonical form.
4484-
if (!IsWindowsSystem && InFact(Flags.BackslashInPath) && _syntax.NotAny(UriSyntaxFlags.ConvertPathSlashes) && _syntax.InFact(UriSyntaxFlags.FileLikeUri) && !IsImplicitFile)
4484+
if (!OperatingSystem.IsWindows() && InFact(Flags.BackslashInPath) && _syntax.NotAny(UriSyntaxFlags.ConvertPathSlashes) && _syntax.InFact(UriSyntaxFlags.FileLikeUri) && !IsImplicitFile)
44854485
{
44864486
// We can't do an in-place escape, create a copy
44874487
var copy = new ValueStringBuilder(stackalloc char[StackallocThreshold]);
@@ -5001,7 +5001,7 @@ private static string CombineUri(Uri basePart, string relativePart, UriFormat ur
50015001
Compress(path, 3, ref length, basePart.Syntax);
50025002
return string.Concat(path.AsSpan(1, length - 1), extra);
50035003
}
5004-
else if (!IsWindowsSystem && basePart.IsUnixPath)
5004+
else if (!OperatingSystem.IsWindows() && basePart.IsUnixPath)
50055005
{
50065006
left = basePart.GetParts(UriComponents.Host, UriFormat.Unescaped);
50075007
}

src/libraries/System.Private.Uri/src/System/UriExt.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private void InitializeUri(ParsingError err, UriKind uriKind, out UriFormatExcep
5656
if (NotAny(Flags.DosPath) &&
5757
uriKind != UriKind.Absolute &&
5858
((uriKind == UriKind.Relative || (_string.Length >= 2 && (_string[0] != '\\' || _string[1] != '\\')))
59-
|| (!IsWindowsSystem && InFact(Flags.UnixPath))))
59+
|| (!OperatingSystem.IsWindows() && InFact(Flags.UnixPath))))
6060
{
6161
_syntax = null!; //make it be relative Uri
6262
_flags &= Flags.UserEscaped; // the only flag that makes sense for a relative uri

0 commit comments

Comments
 (0)