添加元组、AnalysisLevel、DistinctBy 的 PLINQ 形式
This commit is contained in:
1 parent
6e0c722be1
commit
71027af206
2 files changed
+12
-1
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 按对象的指定值去重。
|
||||
/// </summary>
|
||||
public static ParallelQuery<T> DistinctBy<T, TKey>(this ParallelQuery<T> source, Func<T, TKey> selector) {
|
||||
var seen = new ConcurrentDictionary<TKey, bool>();
|
||||
return source.Where(element => seen.TryAdd(selector(element), true));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
<Deterministic>true</Deterministic>
|
||||
<LangVersion>13.0</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<AnalysisLevel>8.0</AnalysisLevel>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -18,6 +19,7 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.ValueTuple" Version="4.6.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in new issue
Block a user