Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions PowerKit/Extensions/AssemblyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// <summary>
/// Reads the specified manifest resource as a string using the specified encoding asynchronously.
/// Throws <see cref="MissingManifestResourceException" /> if the resource is not found.
Expand Down Expand Up @@ -75,6 +76,7 @@ public async Task<string> GetManifestResourceStringAsync(
await assembly
.GetManifestResourceStringAsync(resourceName, Encoding.UTF8, cancellationToken)
.ConfigureAwait(false);
#endif

/// <summary>
/// Extracts the specified manifest resource to a file at the given path.
Expand All @@ -93,6 +95,7 @@ public void ExtractManifestResource(string resourceName, string filePath)
destination.Flush();
}

#if NET40_OR_GREATER || NETSTANDARD || NET
/// <summary>
/// Extracts the specified manifest resource to a file at the given path asynchronously.
/// Throws <see cref="MissingManifestResourceException" /> if the resource is not found.
Expand Down Expand Up @@ -121,5 +124,6 @@ public async Task ExtractManifestResourceAsync(
await source.CopyToAsync(destination, 81920, cancellationToken).ConfigureAwait(false);
await destination.FlushAsync(cancellationToken).ConfigureAwait(false);
}
#endif
}
}
2 changes: 2 additions & 0 deletions PowerKit/Extensions/AsyncEnumerableExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if NET40_OR_GREATER || NETSTANDARD || NET
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -84,3 +85,4 @@ var item in source
public ValueTaskAwaiter<List<T>> GetAwaiter() => source.ToListAsync().GetAwaiter();
}
}
#endif
6 changes: 6 additions & 0 deletions PowerKit/Extensions/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,12 @@ public IEnumerable<string> WhereNotNullOrWhiteSpace()
/// </summary>
public T? LastOrNull()
{
#if NET40_OR_GREATER || NETSTANDARD || NET
if (source is IReadOnlyList<T> list)
{
return list.Count > 0 ? list[list.Count - 1] : null;
}
#endif

var last = default(T?);

Expand All @@ -124,7 +126,11 @@ public IEnumerable<string> WhereNotNullOrWhiteSpace()
/// </summary>
public T? ElementAtOrNull(int index)
{
#if NET40_OR_GREATER || NETSTANDARD || NET
var list = source as IReadOnlyList<T> ?? source.ToArray();
#else
var list = source as IList<T> ?? source.ToArray();
#endif
return index >= 0 && index < list.Count ? list[index] : null;
}
}
Expand Down
5 changes: 5 additions & 0 deletions PowerKit/Extensions/ExceptionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <see cref="AggregateException" /> instances.
/// </summary>
#if NET40_OR_GREATER || NETSTANDARD || NET
public IReadOnlyList<Exception> GetSelfAndDescendants()
#else
public IList<Exception> GetSelfAndDescendants()
#endif
Comment thread
Tyrrrz marked this conversation as resolved.
{
static void PopulateDescendants(Exception ex, ICollection<Exception> result)
{
Expand All @@ -36,3 +40,4 @@ static void PopulateDescendants(Exception ex, ICollection<Exception> result)
}
}
}

2 changes: 2 additions & 0 deletions PowerKit/Extensions/FileExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public static byte[] ReadAllBytes(string path, long offset, int length)
return buffer;
}

#if NET40_OR_GREATER || NETSTANDARD || NET
/// <summary>
/// Reads all bytes from the specified file starting at the given offset asynchronously.
/// </summary>
Comment thread
Tyrrrz marked this conversation as resolved.
Expand Down Expand Up @@ -183,5 +184,6 @@ public static async Task<byte[]> ReadAllBytesAsync(

return buffer;
}
#endif
}
}
2 changes: 2 additions & 0 deletions PowerKit/Extensions/StreamExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ internal static class StreamExtensions
{
extension(Stream source)
{
#if NET40_OR_GREATER || NETSTANDARD || NET
/// <summary>
/// Copies the contents of the stream to the destination stream, optionally flushing after each write.
/// </summary>
Expand Down Expand Up @@ -97,5 +98,6 @@ await source
.CopyToAsync(destination, contentLength, progress, cancellationToken)
.ConfigureAwait(false);
}
#endif
}
}
2 changes: 2 additions & 0 deletions PowerKit/Extensions/TextReaderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ internal static class TextReaderExtensions
{
extension(TextReader reader)
{
#if NET40_OR_GREATER || NETSTANDARD || NET
/// <summary>
/// Reads all lines from the text reader as an async sequence.
/// </summary>
Expand All @@ -23,5 +24,6 @@ await reader.ReadLineAsync(cancellationToken).ConfigureAwait(false) is { } line
yield return line;
}
}
#endif
}
}
2 changes: 1 addition & 1 deletion PowerKit/PowerKit.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net35;net10.0</TargetFrameworks>
Comment thread
Tyrrrz marked this conversation as resolved.
<IsPackable>true</IsPackable>
</PropertyGroup>

Expand Down