mirror of
https://github.com/nsnail/ns-ext.git
synced 2025-06-20 14:38:15 +08:00
feat: ✨ 异步累加器函数
This commit is contained in:
@ -19,7 +19,7 @@ public sealed class ResourceDescriptionAttribute<T> : Attribute
|
||||
/// <summary>
|
||||
/// 资源名称
|
||||
/// </summary>
|
||||
public string ResourceName { get; set; }
|
||||
public string ResourceName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源对象
|
||||
|
@ -5,6 +5,26 @@ namespace NSExt.Extensions;
|
||||
/// </summary>
|
||||
public static class EnumerableExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 异步累加器函数
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException">InvalidOperationException</exception>
|
||||
public static async Task<TSource> AggregateAsync<TSource>( //
|
||||
this IEnumerable<TSource> source, Func<TSource, TSource, Task<TSource>> func)
|
||||
{
|
||||
using var e = source.GetEnumerator();
|
||||
if (!e.MoveNext()) {
|
||||
throw new InvalidOperationException("Sequence contains no elements");
|
||||
}
|
||||
|
||||
var result = e.Current;
|
||||
while (e.MoveNext()) {
|
||||
result = await func(result, e.Current).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将列表转成分隔符分隔的字符串
|
||||
/// </summary>
|
||||
|
@ -26,7 +26,7 @@ public static class StreamExtensions
|
||||
public static bool IsTextStream(this Stream me)
|
||||
{
|
||||
#pragma warning disable IDE0300
|
||||
return me.FirstByteIndex(new byte[] { 0x00, 0xff }) < 0;
|
||||
return me.FirstByteIndex([0x00, 0xff]) < 0;
|
||||
#pragma warning restore IDE0300
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user