From 71027af2066d140d4659ad4c01c29a7572d6a52e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=99=E8=85=BE=E7=8C=AB=E8=B7=83?= <1043137532@qq.com> Date: Wed, 22 Apr 2026 16:23:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=85=83=E7=BB=84=E3=80=81An?= =?UTF-8?q?alysisLevel=E3=80=81DistinctBy=20=E7=9A=84=20PLINQ=20=E5=BD=A2?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Extensions/EnumerableExtensions.cs | 11 ++++++++++- MeloongCore.csproj | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Extensions/EnumerableExtensions.cs b/Extensions/EnumerableExtensions.cs index d968e34..14f57e5 100644 --- a/Extensions/EnumerableExtensions.cs +++ b/Extensions/EnumerableExtensions.cs @@ -1,4 +1,6 @@ -namespace MeloongCore.Extensions; +using System.Collections.Concurrent; + +namespace MeloongCore.Extensions; public static class EnumerableExtensions { #region Distinct @@ -21,6 +23,13 @@ public static class EnumerableExtensions { if (seen.Add(selector(element))) yield return element; } } + /// + /// 按对象的指定值去重。 + /// + public static ParallelQuery DistinctBy(this ParallelQuery source, Func selector) { + var seen = new ConcurrentDictionary(); + return source.Where(element => seen.TryAdd(selector(element), true)); + } #endregion diff --git a/MeloongCore.csproj b/MeloongCore.csproj index 8d0f8e8..9f681fd 100644 --- a/MeloongCore.csproj +++ b/MeloongCore.csproj @@ -11,6 +11,7 @@ true 13.0 enable + 8.0 @@ -18,6 +19,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive +