Skip to content

Commit 5467f71

Browse files
Copilotstephentoub
andcommitted
Add OverloadResolutionPriorityAttribute to AsyncEnumerable overloads with CancellationToken
Co-authored-by: stephentoub <[email protected]>
1 parent 027c512 commit 5467f71

31 files changed

+336
-1
lines changed

src/libraries/System.Linq.AsyncEnumerable/src/System.Linq.AsyncEnumerable.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,15 @@
8888
<Compile Include="System\Linq\Sequence.cs" />
8989
</ItemGroup>
9090

91-
<ItemGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))">
91+
<ItemGroup>
9292
<Compile Include="$(CoreLibSharedDir)System\Runtime\CompilerServices\OverloadResolutionPriorityAttribute.cs" />
9393
</ItemGroup>
9494

95+
<PropertyGroup>
96+
<!-- Suppress warning about duplicate OverloadResolutionPriorityAttribute when building for net10.0 -->
97+
<NoWarn>$(NoWarn);CS0436</NoWarn>
98+
</PropertyGroup>
99+
95100
<ItemGroup Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'">
96101
<ProjectReference Include="$(LibrariesProjectRoot)System.Collections\src\System.Collections.csproj" />
97102
<ProjectReference Include="$(LibrariesProjectRoot)System.Linq\src\System.Linq.csproj" />

src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/AggregateAsync.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ static async ValueTask<TSource> Impl(
6060
/// <exception cref="ArgumentNullException"><paramref name="source"/> is <see langword="null"/>.</exception>
6161
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <see langword="null"/>.</exception>
6262
/// <exception cref="InvalidOperationException"><paramref name="source"/> contains no elements.</exception>
63+
[OverloadResolutionPriority(1)]
6364
public static ValueTask<TSource> AggregateAsync<TSource>(
6465
this IAsyncEnumerable<TSource> source,
6566
Func<TSource, TSource, CancellationToken, ValueTask<TSource>> func,
@@ -139,6 +140,7 @@ static async ValueTask<TAccumulate> Impl(
139140
/// <returns>The final accumulator value.</returns>
140141
/// <exception cref="ArgumentNullException"><paramref name="source"/> is <see langword="null"/>.</exception>
141142
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <see langword="null"/>.</exception>
143+
[OverloadResolutionPriority(1)]
142144
public static ValueTask<TAccumulate> AggregateAsync<TSource, TAccumulate>(
143145
this IAsyncEnumerable<TSource> source, TAccumulate seed,
144146
Func<TAccumulate, TSource, CancellationToken, ValueTask<TAccumulate>> func,
@@ -229,6 +231,7 @@ static async ValueTask<TResult> Impl(
229231
/// <exception cref="ArgumentNullException"><paramref name="source"/> is <see langword="null"/>.</exception>
230232
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <see langword="null"/>.</exception>
231233
/// <exception cref="ArgumentNullException"><paramref name="resultSelector"/> is <see langword="null"/>.</exception>
234+
[OverloadResolutionPriority(1)]
232235
public static ValueTask<TResult> AggregateAsync<TSource, TAccumulate, TResult>(
233236
this IAsyncEnumerable<TSource> source,
234237
TAccumulate seed,

src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/AggregateBy.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ static async IAsyncEnumerable<KeyValuePair<TKey, TAccumulate>> Impl(
101101
/// <exception cref="ArgumentNullException"><paramref name="source"/> is <see langword="null"/>.</exception>
102102
/// <exception cref="ArgumentNullException"><paramref name="keyComparer"/> is <see langword="null"/>.</exception>
103103
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <see langword="null"/>.</exception>
104+
[OverloadResolutionPriority(1)]
104105
public static IAsyncEnumerable<KeyValuePair<TKey, TAccumulate>> AggregateBy<TSource, TKey, TAccumulate>(
105106
this IAsyncEnumerable<TSource> source,
106107
Func<TSource, CancellationToken, ValueTask<TKey>> keySelector,
@@ -240,6 +241,7 @@ static async IAsyncEnumerable<KeyValuePair<TKey, TAccumulate>> Impl(
240241
/// <exception cref="ArgumentNullException"><paramref name="keyComparer"/> is <see langword="null"/>.</exception>
241242
/// <exception cref="ArgumentNullException"><paramref name="seedSelector"/> is <see langword="null"/>.</exception>
242243
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <see langword="null"/>.</exception>
244+
[OverloadResolutionPriority(1)]
243245
public static IAsyncEnumerable<KeyValuePair<TKey, TAccumulate>> AggregateBy<TSource, TKey, TAccumulate>(
244246
this IAsyncEnumerable<TSource> source,
245247
Func<TSource, CancellationToken, ValueTask<TKey>> keySelector,

src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/AllAsync.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public static partial class AsyncEnumerable
2121
/// </returns>
2222
/// <exception cref="ArgumentNullException"><paramref name="source"/> is <see langword="null"/>.</exception>
2323
/// <exception cref="ArgumentNullException"><paramref name="predicate"/> is <see langword="null"/>.</exception>
24+
[OverloadResolutionPriority(1)]
2425
public static ValueTask<bool> AllAsync<TSource>(
2526
this IAsyncEnumerable<TSource> source,
2627
Func<TSource, bool> predicate,

src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/AnyAsync.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public static partial class AsyncEnumerable
1616
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
1717
/// <returns><see langword="true"/> if the source sequence contains any elements; otherwise, <see langword="false"/>.</returns>
1818
/// <exception cref="ArgumentNullException"><paramref name="source"/> is <see langword="null"/>.</exception>
19+
[OverloadResolutionPriority(1)]
1920
public static ValueTask<bool> AnyAsync<TSource>(
2021
this IAsyncEnumerable<TSource> source,
2122
CancellationToken cancellationToken = default)

src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/CountAsync.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public static partial class AsyncEnumerable
1717
/// <returns>The number of elements in the input sequence.</returns>
1818
/// <exception cref="ArgumentNullException"><paramref name="source"/> is <see langword="null"/>.</exception>
1919
/// <exception cref="OverflowException">The number of elements in source is larger than <see cref="int.MaxValue"/> (via the returned task).</exception>
20+
[OverloadResolutionPriority(1)]
2021
public static ValueTask<int> CountAsync<TSource>(
2122
this IAsyncEnumerable<TSource> source,
2223
CancellationToken cancellationToken = default)
@@ -118,6 +119,7 @@ static async ValueTask<int> Impl(
118119
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
119120
/// <returns>The number of elements in the input sequence that satisfy the condition in the predicate function.</returns>
120121
/// <exception cref="ArgumentNullException"><paramref name="source"/> is <see langword="null"/>.</exception>
122+
[OverloadResolutionPriority(1)]
121123
public static ValueTask<long> LongCountAsync<TSource>(
122124
this IAsyncEnumerable<TSource> source,
123125
CancellationToken cancellationToken = default)

src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/CountBy.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ static async IAsyncEnumerable<KeyValuePair<TKey, int>> Impl(
7171
/// <returns>An enumerable containing the frequencies of each key occurrence in <paramref name="source"/>.</returns>
7272
/// <exception cref="ArgumentNullException"><paramref name="source"/> is <see langword="null"/>.</exception>
7373
/// <exception cref="ArgumentNullException"><paramref name="keySelector"/> is <see langword="null"/>.</exception>
74+
[OverloadResolutionPriority(1)]
7475
public static IAsyncEnumerable<KeyValuePair<TKey, int>> CountBy<TSource, TKey>(
7576
this IAsyncEnumerable<TSource> source,
7677
Func<TSource, CancellationToken, ValueTask<TKey>> keySelector,

src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/DistinctBy.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ static async IAsyncEnumerable<TSource> Impl(
7474
/// </remarks>
7575
/// <exception cref="ArgumentNullException"><paramref name="source"/> is <see langword="null"/>.</exception>
7676
/// <exception cref="ArgumentNullException"><paramref name="keySelector"/> is <see langword="null"/>.</exception>
77+
[OverloadResolutionPriority(1)]
7778
public static IAsyncEnumerable<TSource> DistinctBy<TSource, TKey>(
7879
this IAsyncEnumerable<TSource> source,
7980
Func<TSource, CancellationToken, ValueTask<TKey>> keySelector,

src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/ExceptBy.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ static async IAsyncEnumerable<TSource> Impl(
8383
/// <exception cref="ArgumentNullException"><paramref name="first"/> is <see langword="null"/>.</exception>
8484
/// <exception cref="ArgumentNullException"><paramref name="second"/> is <see langword="null"/>.</exception>
8585
/// <exception cref="ArgumentNullException"><paramref name="keySelector"/> is <see langword="null"/>.</exception>
86+
[OverloadResolutionPriority(1)]
8687
public static IAsyncEnumerable<TSource> ExceptBy<TSource, TKey>(
8788
this IAsyncEnumerable<TSource> first,
8889
IAsyncEnumerable<TKey> second,

src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/FirstAsync.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ static async ValueTask<TSource> Impl(
9191
/// The source sequence is empty, or no element in the sequence satisfies
9292
/// the condition in predicate (via the returned task).
9393
/// </exception>
94+
[OverloadResolutionPriority(1)]
9495
public static ValueTask<TSource> FirstAsync<TSource>(
9596
this IAsyncEnumerable<TSource> source,
9697
Func<TSource, CancellationToken, ValueTask<bool>> predicate,
@@ -185,6 +186,7 @@ static async ValueTask<TSource> Impl(
185186
/// </returns>
186187
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
187188
/// <exception cref="ArgumentNullException"><paramref name="predicate" /> is <see langword="null" />.</exception>
189+
[OverloadResolutionPriority(1)]
188190
public static ValueTask<TSource?> FirstOrDefaultAsync<TSource>(
189191
this IAsyncEnumerable<TSource> source,
190192
Func<TSource, CancellationToken, ValueTask<bool>> predicate,
@@ -237,6 +239,7 @@ static async ValueTask<TSource> Impl(
237239
/// <returns><paramref name="defaultValue" /> if <paramref name="source" /> is empty or if no element passes the test specified by <paramref name="predicate" />; otherwise, the first element in <paramref name="source" /> that passes the test specified by <paramref name="predicate" />.</returns>
238240
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
239241
/// <exception cref="ArgumentNullException"><paramref name="predicate" /> is <see langword="null" />.</exception>
242+
[OverloadResolutionPriority(1)]
240243
public static ValueTask<TSource> FirstOrDefaultAsync<TSource>(
241244
this IAsyncEnumerable<TSource> source,
242245
Func<TSource, CancellationToken, ValueTask<bool>> predicate,

0 commit comments

Comments
 (0)