-
Notifications
You must be signed in to change notification settings - Fork 754
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The Big Rename to avoid ambiguity between sync/async/cancellable over…
…loads of operators.
- Loading branch information
1 parent
d2b8eea
commit f2ce04b
Showing
70 changed files
with
5,396 additions
and
5,320 deletions.
There are no files selected for viewing
2,086 changes: 1,043 additions & 1,043 deletions
2,086
Ix.NET/Source/System.Linq.Async.Queryable.Tests/AsyncQueryableTests.Generated.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,382 changes: 691 additions & 691 deletions
1,382
Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncQueryable.Generated.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
Ix.NET/Source/System.Linq.Async.Tests/System/Linq/AsyncEnumerableNamingTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Tests | ||
{ | ||
public class AsyncEnumerableNamingTests | ||
{ | ||
[Fact] | ||
public static void AsyncEnumerable_MethodNames() | ||
{ | ||
var methods = typeof(AsyncEnumerable).GetMethods(BindingFlags.Public | BindingFlags.Static); | ||
|
||
// | ||
// Async suffix | ||
// | ||
|
||
var asyncMethodsNoAsyncSuffix = (from m in methods | ||
where IsTaskLike(m.ReturnType) | ||
where !m.Name.EndsWith("Async") | ||
select m.Name) | ||
.ToArray(); | ||
|
||
Assert.Empty(asyncMethodsNoAsyncSuffix); | ||
|
||
// | ||
// Consistency of delegate types and Await[WithCancellation] naming convention | ||
// | ||
|
||
var methodsWithDelegateParameter = (from m in methods | ||
where m.GetParameters().Any(p => IsAsyncDelegate(p.ParameterType)) | ||
select m) | ||
.ToArray(); | ||
|
||
foreach (var m in methodsWithDelegateParameter) | ||
{ | ||
var kinds = (from p in m.GetParameters() | ||
where IsDelegate(p.ParameterType) | ||
select GetDelegateKind(p.ParameterType)) | ||
.Distinct(); | ||
|
||
Assert.Single(kinds); | ||
|
||
var suffix = IsTaskLike(m.ReturnType) ? "Async" : ""; | ||
|
||
switch (kinds.Single()) | ||
{ | ||
case DelegateKind.Async: | ||
suffix = "Await" + suffix; | ||
break; | ||
case DelegateKind.AsyncCancel: | ||
suffix = "AwaitWithCancellation" + suffix; | ||
break; | ||
} | ||
|
||
Assert.EndsWith(suffix, m.Name); | ||
} | ||
|
||
static bool IsValueTask(Type t) => t == typeof(ValueTask) || (t.IsConstructedGenericType && t.GetGenericTypeDefinition() == typeof(ValueTask<>)); | ||
static bool IsTask(Type t) => typeof(Task).IsAssignableFrom(t); | ||
static bool IsTaskLike(Type t) => IsTask(t) || IsValueTask(t); | ||
|
||
static bool IsDelegate(Type t) => typeof(Delegate).IsAssignableFrom(t); | ||
static bool TryGetInvoke(Type t, out MethodInfo m) => (m = t.GetMethod("Invoke")) != null; | ||
static bool IsAsyncDelegate(Type t) => IsDelegate(t) && TryGetInvoke(t, out var i) && IsTaskLike(i.ReturnType); | ||
static bool IsCancelableDelegate(Type t) => IsDelegate(t) && TryGetInvoke(t, out var i) && i.GetParameters().LastOrDefault()?.ParameterType == typeof(CancellationToken); | ||
static DelegateKind GetDelegateKind(Type t) => IsAsyncDelegate(t) ? (IsCancelableDelegate(t) ? DelegateKind.AsyncCancel : DelegateKind.Async) : DelegateKind.Sync; | ||
} | ||
|
||
private enum DelegateKind | ||
{ | ||
Sync, | ||
Async, | ||
AsyncCancel, | ||
} | ||
} | ||
} |
200 changes: 100 additions & 100 deletions
200
Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/Aggregate.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.