Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
2 changes: 2 additions & 0 deletions PowerKit/Extensions/AssemblyExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if NET40_OR_GREATER || NETSTANDARD || NET
using System.IO;
using System.Reflection;
using System.Resources;
Expand Down Expand Up @@ -123,3 +124,4 @@ public async Task ExtractManifestResourceAsync(
}
}
}
#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
IList<T> list = source.ToArray();
Comment thread
Tyrrrz marked this conversation as resolved.
Outdated
#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 @@ -74,6 +74,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 @@ -136,5 +137,6 @@ public static async Task<byte[]> ReadAllBytesAsync(

return buffer;
}
#endif
}
}
2 changes: 2 additions & 0 deletions PowerKit/Extensions/GuidExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if NET40_OR_GREATER || NETSTANDARD || NET
using System;

namespace PowerKit.Extensions;
Expand All @@ -13,3 +14,4 @@ internal static class GuidExtensions
Guid.TryParse(str, out var result) ? result : null;
}
}
#endif
2 changes: 2 additions & 0 deletions PowerKit/Extensions/StreamExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if NET40_OR_GREATER || NETSTANDARD || NET

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap the methods, nto the whole file. We might add sync extensions later. @copilot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 74a003f — the #if NET40_OR_GREATER || NETSTANDARD || NET guard is now inside the extension(Stream source) block wrapping the methods, with using directives unconditional at the top of the file.

using System;
using System.Buffers;
using System.IO;
Expand Down Expand Up @@ -99,3 +100,4 @@ await source
}
}
}
#endif
2 changes: 2 additions & 0 deletions PowerKit/Extensions/TextReaderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if NET40_OR_GREATER || NETSTANDARD || NET

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap the methods, nto the whole file. We might add sync extensions later. @copilot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 74a003f — same approach as StreamExtensions.cs: #if NET40_OR_GREATER || NETSTANDARD || NET wraps the ReadLinesAsync method inside the extension(TextReader reader) block, with using directives unconditional at the top.

using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -25,3 +26,4 @@ await reader.ReadLineAsync(cancellationToken).ConfigureAwait(false) is { } line
}
}
}
#endif
2 changes: 2 additions & 0 deletions PowerKit/Extensions/TimeSpanExtensions.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.Globalization;

Expand All @@ -21,3 +22,4 @@ internal static class TimeSpanExtensions
TimeSpan.ParseOrNull(str, CultureInfo.CurrentCulture);
}
}
#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