提交 bbd26ab8 编写于 作者: S Sam Harwell

Update SpecializedTasks.Default<T> for C# 9

上级 6ab11eed
......@@ -28,12 +28,12 @@ internal static class SpecializedTasks
=> task!;
[SuppressMessage("Style", "VSTHRD200:Use \"Async\" suffix for async methods", Justification = "This is a Task wrapper, not an asynchronous method.")]
public static Task<T> Default<T>() where T : struct
=> TasksOfStruct<T>.Default;
public static Task<T?> Default<T>()
=> EmptyTasks<T>.Default;
[SuppressMessage("Style", "VSTHRD200:Use \"Async\" suffix for async methods", Justification = "This is a Task wrapper, not an asynchronous method.")]
public static Task<T?> Null<T>() where T : class
=> TasksOfClass<T>.Null;
=> Default<T>();
[SuppressMessage("Style", "VSTHRD200:Use \"Async\" suffix for async methods", Justification = "This is a Task wrapper, not an asynchronous method.")]
public static Task<IReadOnlyList<T>> EmptyReadOnlyList<T>()
......@@ -88,18 +88,9 @@ public static ValueTask<T[]> WhenAll<T>(IEnumerable<ValueTask<T>> tasks)
}
}
private static class TasksOfStruct<T> where T : struct
{
public static readonly Task<T> Default = Task.FromResult<T>(default);
}
private static class TasksOfClass<T> where T : class
{
public static readonly Task<T?> Null = Task.FromResult<T?>(null);
}
private static class EmptyTasks<T>
{
public static readonly Task<T?> Default = Task.FromResult<T?>(default);
public static readonly Task<IEnumerable<T>> EmptyEnumerable = Task.FromResult<IEnumerable<T>>(SpecializedCollections.EmptyEnumerable<T>());
public static readonly Task<ImmutableArray<T>> EmptyImmutableArray = Task.FromResult(ImmutableArray<T>.Empty);
public static readonly Task<IList<T>> EmptyList = Task.FromResult(SpecializedCollections.EmptyList<T>());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册