Родитель
1ff45fbb83
Коммит
3ad0032f89
|
@ -1,6 +1,6 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT License.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
@ -40,5 +40,17 @@ namespace Tests
|
|||
await HasNextAsync(e, "foo");
|
||||
await NoNextAsync(e);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task OfType_NotNullObject()
|
||||
{
|
||||
var xs = new object?[] { 42, null, "foo", null }.ToAsyncEnumerable();
|
||||
var ys = xs.OfType<object>();
|
||||
|
||||
var e = ys.GetAsyncEnumerator();
|
||||
await HasNextAsync(e, 42);
|
||||
await HasNextAsync(e, "foo");
|
||||
await NoNextAsync(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT License.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
@ -25,14 +25,14 @@ namespace System.Linq
|
|||
/// <param name="source">The async-enumerable sequence that contains the elements to be filtered.</param>
|
||||
/// <returns>An async-enumerable sequence that contains elements from the input sequence of type TResult.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
|
||||
public static IAsyncEnumerable<TResult> OfType<TResult>(this IAsyncEnumerable<object> source)
|
||||
public static IAsyncEnumerable<TResult> OfType<TResult>(this IAsyncEnumerable<object?> source)
|
||||
{
|
||||
if (source == null)
|
||||
throw Error.ArgumentNull(nameof(source));
|
||||
|
||||
return Core(source);
|
||||
|
||||
static async IAsyncEnumerable<TResult> Core(IAsyncEnumerable<object> source, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken = default)
|
||||
static async IAsyncEnumerable<TResult> Core(IAsyncEnumerable<object?> source, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken = default)
|
||||
{
|
||||
await foreach (var obj in source.WithCancellation(cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче