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

Expose new String.Split overloads in netcoreapp1.1#12495

Merged
weshaggard merged 3 commits intodotnet:masterfrom
justinvp:string_split
Oct 12, 2016
Merged

Expose new String.Split overloads in netcoreapp1.1#12495
weshaggard merged 3 commits intodotnet:masterfrom
justinvp:string_split

Conversation

@justinvp
Copy link
Copy Markdown
Contributor

@justinvp justinvp commented Oct 9, 2016

Fixes #1513

Also added a test to ensure Split(null) calls Split(char[]) without any compiler ambiguity and some minor test cleanup to reflect that actual overloads that we ended up with.

// The below extension methods allow the tests to run on targets that *do not* have the new Split overloads.
// On targets that *do* have the new Split overloads (e.g. netcoreapp1.1), the actual overloads on String
// are called instead of the extension methods below (due to the way extension methods work).
internal static class StringSplitExtensions
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This seemed much simpler than splitting out the new overloads tests to their own String.SplitTests.netcoreapp1.1.cs file. I also considered creating a StringSplitExtensions.cs that is only included when Condition="'$(TargetGroup)' != 'netcoreapp1.1'", but that seemed overly complex as well.

I confirmed that when running the tests with /p:TargetGroup=netcoreapp1.1, the actual string.Split methods are called instead of the extension methods.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we have any way to verify that at runtime? I'm afraid that we may end up in a place where we accidentally start using these in the future and not catch it. If we don't have any clever way to do that I would prefer we put these in a separate file and condition the inclusion of that file in the project.

@justinvp
Copy link
Copy Markdown
Contributor Author

cc: @weshaggard

Conditionally included only when TargetGroup != netcoreapp1.1.
A perf test was relying on the temporary extension methods in the unit
tests.
Switch over to using one of the older overloads in the perf test.
<Compile Include="Perf.Int32.cs" />
<Compile Include="Perf.IntPtr.cs" />
<Compile Include="Perf.StringBuilder.cs" />
<Compile Include="..\System\String.SplitTests.cs" />
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why remove these tests here, as opposed to including the extensions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the only place where a unit test file is being included in the perf tests. I think it is a mistake. The perf test was written using the temporary extensions methods (I believe as a mistake). It should have been testing one of the older Split overloads, so there's no need to use the extension methods.

#if netcoreapp11
public string[] Split(char separator, System.StringSplitOptions options = System.StringSplitOptions.None) { return default(string[]); }
public string[] Split(char separator, int count, System.StringSplitOptions options = System.StringSplitOptions.None) { return default(string[]); }
public string[] Split(string separator, System.StringSplitOptions options = System.StringSplitOptions.None) { return default(string[]); }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah good, so we did decide to go with @svick's optional parameter idea.

@justinvp
Copy link
Copy Markdown
Contributor Author

@weshaggard, any other feedback?

@weshaggard weshaggard merged commit 9009dc0 into dotnet:master Oct 12, 2016
@weshaggard
Copy link
Copy Markdown
Member

Thanks @justinvp

@justinvp justinvp deleted the string_split branch October 15, 2016 15:56
@karelz karelz modified the milestone: 1.2.0 Dec 3, 2016
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Expose new String.Split overloads in netcoreapp1.1

Commit migrated from dotnet/corefx@9009dc0
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants