From ddf07fce5732e576db1512f870196c20f7b297e2 Mon Sep 17 00:00:00 2001 From: tk Date: Fri, 1 Mar 2024 11:23:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20=E5=BC=82=E6=AD=A5=E7=B4=AF?= =?UTF-8?q?=E5=8A=A0=E5=99=A8=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/code.quality.props | 8 +++--- scripts/switcher.nsext.json | 17 ------------ scripts/switcher.ps1 | 27 ------------------- src/backend/NSExt.Tests/NSExt.Tests.csproj | 6 ++--- .../ResourceDescriptionAttribute.cs | 2 +- .../NSExt/Extensions/EnumerableExtensions.cs | 20 ++++++++++++++ .../NSExt/Extensions/StreamExtensions.cs | 2 +- 7 files changed, 29 insertions(+), 53 deletions(-) delete mode 100644 scripts/switcher.nsext.json delete mode 100644 scripts/switcher.ps1 diff --git a/build/code.quality.props b/build/code.quality.props index facdab9..c9025f2 100644 --- a/build/code.quality.props +++ b/build/code.quality.props @@ -11,19 +11,19 @@ true - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/scripts/switcher.nsext.json b/scripts/switcher.nsext.json deleted file mode 100644 index 118955a..0000000 --- a/scripts/switcher.nsext.json +++ /dev/null @@ -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" - } - ] - } - ] -} \ No newline at end of file diff --git a/scripts/switcher.ps1 b/scripts/switcher.ps1 deleted file mode 100644 index 41dafe7..0000000 --- a/scripts/switcher.ps1 +++ /dev/null @@ -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 \ No newline at end of file diff --git a/src/backend/NSExt.Tests/NSExt.Tests.csproj b/src/backend/NSExt.Tests/NSExt.Tests.csproj index a81c311..571955e 100644 --- a/src/backend/NSExt.Tests/NSExt.Tests.csproj +++ b/src/backend/NSExt.Tests/NSExt.Tests.csproj @@ -1,11 +1,11 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/backend/NSExt/Attributes/ResourceDescriptionAttribute.cs b/src/backend/NSExt/Attributes/ResourceDescriptionAttribute.cs index c2e4386..3a99680 100644 --- a/src/backend/NSExt/Attributes/ResourceDescriptionAttribute.cs +++ b/src/backend/NSExt/Attributes/ResourceDescriptionAttribute.cs @@ -19,7 +19,7 @@ public sealed class ResourceDescriptionAttribute : Attribute /// /// 资源名称 /// - public string ResourceName { get; set; } + public string ResourceName { get; } /// /// 资源对象 diff --git a/src/backend/NSExt/Extensions/EnumerableExtensions.cs b/src/backend/NSExt/Extensions/EnumerableExtensions.cs index 08eef9f..a1101f3 100644 --- a/src/backend/NSExt/Extensions/EnumerableExtensions.cs +++ b/src/backend/NSExt/Extensions/EnumerableExtensions.cs @@ -5,6 +5,26 @@ namespace NSExt.Extensions; /// public static class EnumerableExtensions { + /// + /// 异步累加器函数 + /// + /// InvalidOperationException + public static async Task AggregateAsync( // + this IEnumerable source, Func> 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; + } + /// /// 将列表转成分隔符分隔的字符串 /// diff --git a/src/backend/NSExt/Extensions/StreamExtensions.cs b/src/backend/NSExt/Extensions/StreamExtensions.cs index 0c8e61e..fff1316 100644 --- a/src/backend/NSExt/Extensions/StreamExtensions.cs +++ b/src/backend/NSExt/Extensions/StreamExtensions.cs @@ -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 } } \ No newline at end of file