Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
Add support for netstandard2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed Dec 4, 2021
1 parent 5c3f6e7 commit dbe24b6
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 47 deletions.
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>2.4.1</Version>
<Version>3.0.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -26,7 +26,7 @@
<RepositoryBranch>main</RepositoryBranch>
<RepositoryType>Git</RepositoryType>
<RepositoryUrl>https://github.com/JustArchiNET/Madness.git</RepositoryUrl>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
</PropertyGroup>

<!-- Default configuration for fast-debugging builds -->
Expand Down
7 changes: 5 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
<ItemGroup>
<PackageVersion Include="ConfigureAwaitChecker.Analyzer" Version="5.0.0" />
<PackageVersion Include="JetBrains.Annotations" Version="2021.3.0" />
<PackageVersion Include="IndexRange" Version="1.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="1.0.0" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="1.0.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageVersion Include="IndexRange" Version="1.0.0" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="1.0.0" />
<PackageVersion Include="System.Memory" Version="4.5.0" />
</ItemGroup>
</Project>
20 changes: 20 additions & 0 deletions JustArchiNET.Madness/FileMadness/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@ public static class File {
[MadnessType(EMadnessType.Proxy)]
public static void AppendAllText(string path, string? contents) => System.IO.File.AppendAllText(path, contents);

#if NETSTANDARD2_1_OR_GREATER
[MadnessType(EMadnessType.Proxy)]
public static Task AppendAllTextAsync(string path, string? contents) => System.IO.File.AppendAllTextAsync(path, contents);
#else
[MadnessType(EMadnessType.Implementation)]
public static Task AppendAllTextAsync(string path, string? contents) {
AppendAllText(path, contents);

return Task.CompletedTask;
}
#endif

[MadnessType(EMadnessType.Proxy)]
public static void Delete(string path) => System.IO.File.Delete(path);
Expand All @@ -63,25 +68,40 @@ public static void Move(string sourceFileName, string destFileName, bool overwri
[MadnessType(EMadnessType.Proxy)]
public static byte[] ReadAllBytes(string path) => System.IO.File.ReadAllBytes(path);

#if NETSTANDARD2_1_OR_GREATER
[MadnessType(EMadnessType.Proxy)]
public static Task<byte[]> ReadAllBytesAsync(string path) => System.IO.File.ReadAllBytesAsync(path);
#else
[MadnessType(EMadnessType.Implementation)]
public static Task<byte[]> ReadAllBytesAsync(string path) => Task.FromResult(ReadAllBytes(path));
#endif

[MadnessType(EMadnessType.Proxy)]
public static string ReadAllText(string path) => System.IO.File.ReadAllText(path);

#if NETSTANDARD2_1_OR_GREATER
[MadnessType(EMadnessType.Proxy)]
public static Task<string> ReadAllTextAsync(string path) => System.IO.File.ReadAllTextAsync(path);
#else
[MadnessType(EMadnessType.Implementation)]
public static Task<string> ReadAllTextAsync(string path) => Task.FromResult(ReadAllText(path));
#endif

[MadnessType(EMadnessType.Proxy)]
public static void Replace(string sourceFileName, string destinationFileName, string? destinationBackupFileName) => System.IO.File.Replace(sourceFileName, destinationFileName, destinationBackupFileName);

[MadnessType(EMadnessType.Proxy)]
public static void WriteAllText(string path, string? contents) => System.IO.File.WriteAllText(path, contents);

#if NETSTANDARD2_1_OR_GREATER
[MadnessType(EMadnessType.Proxy)]
public static Task WriteAllTextAsync(string path, string? contents) => System.IO.File.WriteAllTextAsync(path, contents);
#else
[MadnessType(EMadnessType.Implementation)]
public static Task WriteAllTextAsync(string path, string? contents) {
WriteAllText(path, contents);

return Task.CompletedTask;
}
#endif
}
11 changes: 11 additions & 0 deletions JustArchiNET.Madness/HashCodeMadness/HashCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ namespace JustArchiNET.Madness.HashCodeMadness;
[MadnessType(EMadnessType.Implementation)]
[PublicAPI]
public static class HashCode {
#if NETSTANDARD2_1_OR_GREATER
[MadnessType(EMadnessType.Proxy)]
public static int Combine<T1, T2>(T1 value1, T2 value2) => System.HashCode.Combine(value1, value2);

[MadnessType(EMadnessType.Proxy)]
public static int Combine<T1, T2, T3>(T1 value1, T2 value2, T3 value3) => System.HashCode.Combine(value1, value2, value3);

[MadnessType(EMadnessType.Proxy)]
public static int Combine<T1, T2, T3, T4>(T1 value1, T2 value2, T3 value3, T4 value4) => System.HashCode.Combine(value1, value2, value3, value4);
#else
[MadnessType(EMadnessType.Implementation)]
public static int Combine<T1, T2>(T1 value1, T2 value2) => (value1, value2).GetHashCode();

Expand All @@ -35,4 +45,5 @@ public static class HashCode {

[MadnessType(EMadnessType.Implementation)]
public static int Combine<T1, T2, T3, T4>(T1 value1, T2 value2, T3 value3, T4 value4) => (value1, value2, value3, value4).GetHashCode();
#endif
}
2 changes: 2 additions & 0 deletions JustArchiNET.Madness/Internal/AsyncDisposableWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if !NETSTANDARD2_1_OR_GREATER
using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
Expand All @@ -37,3 +38,4 @@ public ValueTask DisposeAsync() {
return default(ValueTask);
}
}
#endif
2 changes: 2 additions & 0 deletions JustArchiNET.Madness/Internal/PathInternalNetCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if !NETSTANDARD2_1_OR_GREATER
using System;
using System.IO;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -167,3 +168,4 @@ private static int GetRootLength(string path) {
return i;
}
}
#endif
7 changes: 5 additions & 2 deletions JustArchiNET.Madness/JustArchiNET.Madness.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

<ItemGroup>
<PackageReference Include="ConfigureAwaitChecker.Analyzer" PrivateAssets="all" />
<PackageReference Include="IndexRange" />
<PackageReference Include="JetBrains.Annotations" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="all" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="IndexRange" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" />
<PackageReference Include="System.Memory" />
</ItemGroup>

Expand Down
9 changes: 8 additions & 1 deletion JustArchiNET.Madness/PathMadness/Path.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if !NETSTANDARD2_1_OR_GREATER
using System;
using System.Text;
using JustArchiNET.Madness.Internal;
#endif
using JetBrains.Annotations;
using JustArchiNET.Madness.Helpers;
using JustArchiNET.Madness.Internal;

namespace JustArchiNET.Madness.PathMadness;

Expand Down Expand Up @@ -63,6 +65,10 @@ public static class Path {
[Pure]
public static string GetFullPath(string path) => System.IO.Path.GetFullPath(path);

#if NETSTANDARD2_1_OR_GREATER
[MadnessType(EMadnessType.Proxy)]
public static string GetRelativePath(string relativeTo, string path) => System.IO.Path.GetRelativePath(relativeTo, path);
#else
[MadnessType(EMadnessType.Implementation)]
public static string GetRelativePath(string relativeTo, string path) {
if (string.IsNullOrEmpty(relativeTo)) {
Expand Down Expand Up @@ -157,6 +163,7 @@ public static string GetRelativePath(string relativeTo, string path) {

return sb.ToString(); //StringBuilderCache.GetStringAndRelease(sb);
}
#endif

[MadnessType(EMadnessType.Proxy)]
public static string GetTempPath() => System.IO.Path.GetTempPath();
Expand Down
50 changes: 10 additions & 40 deletions JustArchiNET.Madness/StaticExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
#if !NETSTANDARD2_1_OR_GREATER
using System.Collections.Generic;
using System.IO;
using System.Net.WebSockets;
using System.Threading;
using JustArchiNET.Madness.Internal;
#endif
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using JustArchiNET.Madness.Helpers;
using JustArchiNET.Madness.Internal;
using Microsoft.AspNetCore.Hosting;

namespace JustArchiNET.Madness;
Expand Down Expand Up @@ -59,6 +61,7 @@ public static Task<byte[]> ComputeHashAsync(this HashAlgorithm hashAlgorithm, St
return Task.FromResult(hashAlgorithm.ComputeHash(inputStream));
}

#if !NETSTANDARD2_1_OR_GREATER
[MadnessType(EMadnessType.Implementation)]
public static IAsyncDisposable ConfigureAwait(this IDisposable source, bool continueOnCapturedContext) {
if (source == null) {
Expand All @@ -67,33 +70,8 @@ public static IAsyncDisposable ConfigureAwait(this IDisposable source, bool cont

return new AsyncDisposableWrapper(source, continueOnCapturedContext);
}
#endif

/// <summary>
/// Configures a <see cref="IWebHostBuilder" /> with defaults for hosting a web app.
/// </summary>
/// <remarks>
/// The following defaults are applied to the <see cref="IWebHostBuilder" />:
/// <list type="bullet">
/// <item>
/// <description>use Kestrel as the web server and configure it using the application's configuration providers</description>
/// </item>
/// <item>
/// <description>configure <see cref="IHostingEnvironment.WebRootFileProvider" /> to include static web assets from projects referenced by the entry assembly during development</description>
/// </item>
/// <item>
/// <description>adds the HostFiltering middleware</description>
/// </item>
/// <item>
/// <description>adds the ForwardedHeaders middleware if ASPNETCORE_FORWARDEDHEADERS_ENABLED=true,</description>
/// </item>
/// <item>
/// <description>enable IIS integration</description>
/// </item>
/// </list>
/// </remarks>
/// <param name="builder">The <see cref="IWebHostBuilder" /> instance to configure.</param>
/// <param name="configure">The configure callback</param>
/// <returns>A reference to the <paramref name="builder" /> after the operation has completed.</returns>
[MadnessType(EMadnessType.Implementation)]
public static IWebHostBuilder ConfigureWebHostDefaults(this IWebHostBuilder builder, Action<IWebHostBuilder> configure) {
if (configure == null) {
Expand All @@ -105,6 +83,7 @@ public static IWebHostBuilder ConfigureWebHostDefaults(this IWebHostBuilder buil
return builder;
}

#if !NETSTANDARD2_1_OR_GREATER
[MadnessType(EMadnessType.Implementation)]
public static bool Contains(this string input, char value) {
if (input == null) {
Expand Down Expand Up @@ -238,16 +217,6 @@ public static string[] Split(this string text, char separator, StringSplitOption
return text.Split(new[] { separator }, options);
}

/// <summary>
/// Sets the capacity of this dictionary to what it would be if it had been originally initialized with all its entries
/// </summary>
/// <remarks>
/// This method can be used to minimize the memory overhead
/// once it is known that no new elements will be added.
/// To allocate minimum size storage array, execute the following statements:
/// dictionary.Clear();
/// dictionary.TrimExcess();
/// </remarks>
[MadnessType(EMadnessType.Implementation)]
public static void TrimExcess<TKey, TValue>(this Dictionary<TKey, TValue> _) { } // no-op

Expand All @@ -271,4 +240,5 @@ private static ValueTask FakeDisposeAsync(IDisposable? disposable) {

return default(ValueTask);
}
#endif
}
9 changes: 9 additions & 0 deletions JustArchiNET.Madness/StringMadness/String.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if NETSTANDARD2_1_OR_GREATER
using System.Buffers;
#else
using System;
#endif
using JetBrains.Annotations;
using JustArchiNET.Madness.Helpers;

Expand All @@ -29,6 +33,10 @@ namespace JustArchiNET.Madness.StringMadness;
[MadnessType(EMadnessType.Replacement)]
[PublicAPI]
public static class String {
#if NETSTANDARD2_1_OR_GREATER
[MadnessType(EMadnessType.Proxy)]
public static string Create<TState>(int length, TState state, SpanAction<char, TState> action) => string.Create(length, state, action);
#else
[MadnessType(EMadnessType.Implementation)]
public delegate void SpanAction<T, in TArg>(Span<T> span, TArg arg);

Expand All @@ -51,6 +59,7 @@ public static string Create<TState>(int length, TState state, SpanAction<char, T

return new string(buffer);
}
#endif

[ContractAnnotation("null=>true", true)]
[MadnessType(EMadnessType.Proxy)]
Expand Down

0 comments on commit dbe24b6

Please sign in to comment.