-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add .NET Standard 2.0 and .NET 6 targets (#8)
Resolves #7
- Loading branch information
Showing
6 changed files
with
112 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#if NETSTANDARD2_0 | ||
|
||
using System.Runtime.InteropServices; | ||
|
||
namespace Sqids; | ||
|
||
internal static class PolyfillExtensions | ||
{ | ||
public static StringBuilder Append(this StringBuilder builder, ReadOnlySpan<char> value) | ||
{ | ||
if (builder is null) throw new ArgumentNullException(nameof(builder)); | ||
|
||
if (!value.IsEmpty) | ||
{ | ||
unsafe | ||
{ | ||
fixed (char* p = &MemoryMarshal.GetReference(value)) | ||
{ | ||
builder.Append(p, value.Length); | ||
} | ||
} | ||
} | ||
|
||
return builder; | ||
} | ||
|
||
public static StringBuilder Insert(this StringBuilder builder, int index, ReadOnlySpan<char> value) | ||
{ | ||
if (builder is null) throw new ArgumentNullException(nameof(builder)); | ||
|
||
if (!value.IsEmpty) | ||
{ | ||
// NOTE: Unfortunately, not much we can do here; the StringBuilder.Insert(int, char*, int) method is private. | ||
char[] temp = new char[value.Length]; | ||
value.CopyTo(temp); | ||
builder.Insert(index, temp); | ||
} | ||
|
||
return builder; | ||
} | ||
|
||
public static bool Contains(this Span<char> source, char toFind) => | ||
source.IndexOf(toFind) != -1; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,32 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<!-- NOTE: `net472` is used for testing `netstandard2.0` --> | ||
<TargetFrameworks>net472;net6.0;net7.0</TargetFrameworks> | ||
<LangVersion>11.0</LangVersion> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" /> | ||
<PackageReference Include="NUnit" Version="3.13.3" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" /> | ||
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" /> | ||
<PackageReference Include="coverlet.collector" Version="3.2.0" /> | ||
<PackageReference Include="Shouldly" Version="4.2.1" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" /> | ||
<PackageReference Include="NUnit" Version="3.13.3" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" /> | ||
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" /> | ||
<PackageReference Include="coverlet.collector" Version="3.2.0" /> | ||
<PackageReference Include="Shouldly" Version="4.2.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Sqids\Sqids.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Sqids\Sqids.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition="'$(TargetFramework)'=='netstandard2.0'"> | ||
<PackageReference Include="PolySharp" Version="1.13.2"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
</Project> |