Skip to content

Commit

Permalink
string static
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Mar 25, 2023
1 parent 2293b91 commit 3f3438e
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 23 deletions.
53 changes: 53 additions & 0 deletions src/Polyfill/PolyString.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#pragma warning disable

// ReSharper disable RedundantUsingDirective
// ReSharper disable PartialTypeWithSinglePart

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
#if PolyPublic
public
#endif
static partial class PolyString
{
public static string Join(char separator, string[] values)
{
#if NETSTANDARD2_0 || NETFRAMEWORK
return string.Join(new(new[]{separator}), values);
#else
return string.Join(separator, values);
#endif
}

public static string Join(char separator, object[] values)
{
#if NETSTANDARD2_0 || NETFRAMEWORK
return string.Join(new(new[]{separator}), values);
#else
return string.Join(separator, values);
#endif
}

public static string Join (char separator, string?[] value, int startIndex, int count)
{
#if NETSTANDARD2_0 || NETFRAMEWORK
return string.Join(new(new[]{separator}), value, startIndex, count);
#else
return string.Join(separator, value, startIndex, count);
#endif
}

public static string Join<T> (char separator, IEnumerable<T> values)
{
#if NETSTANDARD2_0 || NETFRAMEWORK
return string.Join(new(new[]{separator}), values);
#else
return string.Join(separator, values);
#endif
}
}
12 changes: 12 additions & 0 deletions src/Tests/PolyStringTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// ReSharper disable PartialTypeWithSinglePart

[TestFixture]
partial class PolyStringTest
{
[Test]
public void Join()
{
Assert.AreEqual("bac", PolyString.Join('a', new []{"b","c"}));
Assert.AreEqual("bac", PolyString.Join('a', new object[]{"b","c"}));
}
}
1 change: 0 additions & 1 deletion src/Tests/PolyfillExtensionsSample.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// ReSharper disable PartialTypeWithSinglePart

[TestFixture]
[DebuggerNonUserCode]
partial class PolyfillExtensionsSample
{
[Test]
Expand Down
29 changes: 7 additions & 22 deletions src/Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,13 @@
<Link>Pollyfill\PlatformCompatibility\%(RecursiveDir)%(Filename).cs</Link>
</Compile>
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter"
Version="4.4.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk"
Version="17.5.0" />
<PackageReference Include="MarkdownSnippets.MsBuild"
Version="24.5.1" />
<PackageReference Include="ProjectDefaults"
Version="1.0.90"
PrivateAssets="all" />
<PackageReference Include="System.Memory"
Version="4.5.5"
Condition="$(TargetFrameworkIdentifier) == '.NETStandard' or
$(TargetFrameworkIdentifier) == '.NETFramework' or
$(TargetFramework.StartsWith('netcoreapp2'))" />
<PackageReference Include="System.ValueTuple"
Version="4.5.0"
Condition="$(TargetFramework.StartsWith('net46'))" />
<PackageReference Include="System.Threading.Tasks.Extensions"
Version="4.5.4"
Condition="$(TargetFramework) == 'netstandard2.0' or
$(TargetFramework) == 'netcoreapp2.0' or
$(TargetFrameworkIdentifier) == '.NETFramework'" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="MarkdownSnippets.MsBuild" Version="24.5.1" />
<PackageReference Include="ProjectDefaults" Version="1.0.90" PrivateAssets="all" />
<PackageReference Include="System.Memory" Version="4.5.5" Condition="$(TargetFrameworkIdentifier) == '.NETStandard' or&#xD;&#xA; $(TargetFrameworkIdentifier) == '.NETFramework' or&#xD;&#xA; $(TargetFramework.StartsWith('netcoreapp2'))" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" Condition="$(TargetFramework.StartsWith('net46'))" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" Condition="$(TargetFramework) == 'netstandard2.0' or&#xD;&#xA; $(TargetFramework) == 'netcoreapp2.0' or&#xD;&#xA; $(TargetFrameworkIdentifier) == '.NETFramework'" />
</ItemGroup>
<Import Project="$(ProjectDir)..\Polyfill\Polyfill.props" />
<Import Project="$(ProjectDir)..\Polyfill\Polyfill.targets" />
Expand Down

0 comments on commit 3f3438e

Please sign in to comment.