feat: 异步累加器函数 (#17)

This commit is contained in:
nsnail 2024-03-01 11:24:47 +08:00 committed by GitHub
parent 00164b02d9
commit 3de9d3b8d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 29 additions and 53 deletions

View File

@ -11,19 +11,19 @@
<WarningsAsErrors>true</WarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.507">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.9.1-alpha">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.9.28">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Roslynator.Analyzers" Version="4.7.0">
<PackageReference Include="Roslynator.Analyzers" Version="4.11.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.15.0.81779">
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.20.0.85982">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

View File

@ -1,17 +0,0 @@
{
"solution": "NSExt.sln",
"mappings": {
"NSExt": "../refs/ns-ext/src/NSExt/NSExt.csproj"
},
"restore": [
{
"name": "NSExt",
"packages": [
{
"packageName": "NSExt",
"version": "1.1.0"
}
]
}
]
}

View File

@ -1,27 +0,0 @@
# https://github.com/RicoSuter/DNT#switch-to-projects
$targets = @{
'1' = 'switch-to-projects'
'2' = 'switch-to-packages'
}
$key = ''
while ($null -eq $targets[$key])
{
$key = 读取-Host '请选择1切换到项目引用 2切换到Nuget包引用'
}
$files = Get-ChildItem Switcher.*.json
$file = 9999
while ($null -eq $files[[int]$file - 1])
{
$i = 0
Write-Host '请选择要切换的配置文件文件'
foreach ($file in $files)
{
$i++
Write-Host $i $file.Name
}
$file = 读取-Host
}
$file = [int]$file - 1
Copy-Item $files[$file] 'switcher.json' -Force
dotnet dnt $targets[$key] ../NSExt.sln
Remove-Item switcher.json

View File

@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="xunit" Version="2.6.3"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.5">
<PackageReference Include="xunit" Version="2.7.0"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PackageReference Include="coverlet.collector" Version="6.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>

View File

@ -19,7 +19,7 @@ public sealed class ResourceDescriptionAttribute<T> : Attribute
/// <summary>
/// 资源名称
/// </summary>
public string ResourceName { get; set; }
public string ResourceName { get; }
/// <summary>
/// 资源对象

View File

@ -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>

View File

@ -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
}
}