diff --git a/PowerKit/Extensions/AssemblyExtensions.cs b/PowerKit/Extensions/AssemblyExtensions.cs
index 4264bb0..74d4786 100644
--- a/PowerKit/Extensions/AssemblyExtensions.cs
+++ b/PowerKit/Extensions/AssemblyExtensions.cs
@@ -44,6 +44,7 @@ public string GetManifestResourceString(string resourceName, Encoding encoding)
public string GetManifestResourceString(string resourceName) =>
assembly.GetManifestResourceString(resourceName, Encoding.UTF8);
+#if NET40_OR_GREATER || NETSTANDARD || NET
///
/// Reads the specified manifest resource as a string using the specified encoding asynchronously.
/// Throws if the resource is not found.
@@ -75,6 +76,7 @@ public async Task GetManifestResourceStringAsync(
await assembly
.GetManifestResourceStringAsync(resourceName, Encoding.UTF8, cancellationToken)
.ConfigureAwait(false);
+#endif
///
/// Extracts the specified manifest resource to a file at the given path.
@@ -93,6 +95,7 @@ public void ExtractManifestResource(string resourceName, string filePath)
destination.Flush();
}
+#if NET40_OR_GREATER || NETSTANDARD || NET
///
/// Extracts the specified manifest resource to a file at the given path asynchronously.
/// Throws if the resource is not found.
@@ -121,5 +124,6 @@ public async Task ExtractManifestResourceAsync(
await source.CopyToAsync(destination, 81920, cancellationToken).ConfigureAwait(false);
await destination.FlushAsync(cancellationToken).ConfigureAwait(false);
}
+#endif
}
}
diff --git a/PowerKit/Extensions/AsyncEnumerableExtensions.cs b/PowerKit/Extensions/AsyncEnumerableExtensions.cs
index ec506f9..29f7134 100644
--- a/PowerKit/Extensions/AsyncEnumerableExtensions.cs
+++ b/PowerKit/Extensions/AsyncEnumerableExtensions.cs
@@ -1,3 +1,4 @@
+#if NET40_OR_GREATER || NETSTANDARD || NET
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
@@ -84,3 +85,4 @@ var item in source
public ValueTaskAwaiter> GetAwaiter() => source.ToListAsync().GetAwaiter();
}
}
+#endif
diff --git a/PowerKit/Extensions/EnumerableExtensions.cs b/PowerKit/Extensions/EnumerableExtensions.cs
index d7be50a..a2eebf4 100644
--- a/PowerKit/Extensions/EnumerableExtensions.cs
+++ b/PowerKit/Extensions/EnumerableExtensions.cs
@@ -104,10 +104,12 @@ public IEnumerable WhereNotNullOrWhiteSpace()
///
public T? LastOrNull()
{
+#if NET40_OR_GREATER || NETSTANDARD || NET
if (source is IReadOnlyList list)
{
return list.Count > 0 ? list[list.Count - 1] : null;
}
+#endif
var last = default(T?);
@@ -124,7 +126,11 @@ public IEnumerable WhereNotNullOrWhiteSpace()
///
public T? ElementAtOrNull(int index)
{
+#if NET40_OR_GREATER || NETSTANDARD || NET
var list = source as IReadOnlyList ?? source.ToArray();
+#else
+ var list = source as IList ?? source.ToArray();
+#endif
return index >= 0 && index < list.Count ? list[index] : null;
}
}
diff --git a/PowerKit/Extensions/ExceptionExtensions.cs b/PowerKit/Extensions/ExceptionExtensions.cs
index 08cd54c..534ac8a 100644
--- a/PowerKit/Extensions/ExceptionExtensions.cs
+++ b/PowerKit/Extensions/ExceptionExtensions.cs
@@ -11,7 +11,11 @@ internal static class ExceptionExtensions
/// Returns a flat list containing the exception itself and all of its
/// nested inner exceptions, recursively unwrapping instances.
///
+#if NET40_OR_GREATER || NETSTANDARD || NET
public IReadOnlyList GetSelfAndDescendants()
+#else
+ public IList GetSelfAndDescendants()
+#endif
{
static void PopulateDescendants(Exception ex, ICollection result)
{
@@ -36,3 +40,4 @@ static void PopulateDescendants(Exception ex, ICollection result)
}
}
}
+
diff --git a/PowerKit/Extensions/FileExtensions.cs b/PowerKit/Extensions/FileExtensions.cs
index 402104c..e26f970 100644
--- a/PowerKit/Extensions/FileExtensions.cs
+++ b/PowerKit/Extensions/FileExtensions.cs
@@ -121,6 +121,7 @@ public static byte[] ReadAllBytes(string path, long offset, int length)
return buffer;
}
+#if NET40_OR_GREATER || NETSTANDARD || NET
///
/// Reads all bytes from the specified file starting at the given offset asynchronously.
///
@@ -183,5 +184,6 @@ public static async Task ReadAllBytesAsync(
return buffer;
}
+#endif
}
}
diff --git a/PowerKit/Extensions/StreamExtensions.cs b/PowerKit/Extensions/StreamExtensions.cs
index cb865a1..8efe130 100644
--- a/PowerKit/Extensions/StreamExtensions.cs
+++ b/PowerKit/Extensions/StreamExtensions.cs
@@ -10,6 +10,7 @@ internal static class StreamExtensions
{
extension(Stream source)
{
+#if NET40_OR_GREATER || NETSTANDARD || NET
///
/// Copies the contents of the stream to the destination stream, optionally flushing after each write.
///
@@ -97,5 +98,6 @@ await source
.CopyToAsync(destination, contentLength, progress, cancellationToken)
.ConfigureAwait(false);
}
+#endif
}
}
diff --git a/PowerKit/Extensions/TextReaderExtensions.cs b/PowerKit/Extensions/TextReaderExtensions.cs
index 72acb84..1f48311 100644
--- a/PowerKit/Extensions/TextReaderExtensions.cs
+++ b/PowerKit/Extensions/TextReaderExtensions.cs
@@ -9,6 +9,7 @@ internal static class TextReaderExtensions
{
extension(TextReader reader)
{
+#if NET40_OR_GREATER || NETSTANDARD || NET
///
/// Reads all lines from the text reader as an async sequence.
///
@@ -23,5 +24,6 @@ await reader.ReadLineAsync(cancellationToken).ConfigureAwait(false) is { } line
yield return line;
}
}
+#endif
}
}
diff --git a/PowerKit/PowerKit.csproj b/PowerKit/PowerKit.csproj
index 4c39f87..39e4e7c 100644
--- a/PowerKit/PowerKit.csproj
+++ b/PowerKit/PowerKit.csproj
@@ -1,6 +1,6 @@
- netstandard2.0
+ netstandard2.0;net35;net10.0
true