Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Add Path.Join string overloads #18458

Merged
merged 2 commits into from
Jun 14, 2018
Merged

Add Path.Join string overloads #18458

merged 2 commits into from
Jun 14, 2018

Conversation

MarcoRossignoli
Copy link
Member

Copy link
Member

@JeremyKuhne JeremyKuhne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@@ -409,6 +409,16 @@ public static string Join(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2, Re
return JoinInternal(path1, path2, path3);
}

public static string Join(string path1, string path2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are going to end up treating null strings the same as empty strings. Do we instead want to match the behavior of Path.Combine, which throws ArgumentNullException for null strings?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key thing here is that we've shipped this way already. As is illustrated here, ((string)null).AsSpan() gives you default, it doesn't throw. Same goes for the implicit conversion- presumably adding the throw would be a breaking change for those relying on that.

Outside of that I'd rather they don't throw as they'll never throw for the span versions. I'm more inclined to be consistent within the overloads. I don't plan to ever add a span version to Combine as I want to discourage usage- if I thought that likely I might sway a little, but still not enough to want to throw I think.

@pjanotti do you have an opinion?

Copy link
Member

@stephentoub stephentoub Jun 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key thing here is that we've shipped this way already. As is illustrated here, ((string)null).AsSpan() gives you default, it doesn't throw.

Ugh, you're right. Ok, we should keep it the way it is; otherwise adding these overloads would change behavior against 2.1 when code is recompiled.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do Path.Join(String.Empty, (string)null) today. It compiles and runs fine thanks to implicit string->span conversion. This code will pick up the new string overload once it is added. It is preferable for the new string overload to have same behavior as the Span version to avoid breaking change on recompile.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, that's what I was agreeing with.

@stephentoub stephentoub merged commit 5b23086 into dotnet:master Jun 14, 2018
dotnet-bot pushed a commit to dotnet/corert that referenced this pull request Jun 14, 2018
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
@MarcoRossignoli MarcoRossignoli deleted the joinoverloads branch June 14, 2018 17:43
MichalStrehovsky pushed a commit to dotnet/corert that referenced this pull request Jun 14, 2018
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
dotnet-bot pushed a commit to dotnet/corefx that referenced this pull request Jun 17, 2018
Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
jkotas pushed a commit to dotnet/corefx that referenced this pull request Jun 17, 2018
Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
@karelz karelz added this to the 3.0 milestone Nov 15, 2018
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
5 participants