未验证 提交 3d74b006 编写于 作者: S Stephen Toub 提交者: GitHub

Enable nullable for Microsoft.Bcl.AsyncInterfaces (#70454)

* Enable nullable for Microsoft.Bcl.AsyncInterfaces

* Apply suggestions from code review
Co-authored-by: NEric Erhardt <eric.erhardt@microsoft.com>
Co-authored-by: NEric Erhardt <eric.erhardt@microsoft.com>
上级 fcbf91d0
......@@ -88,7 +88,7 @@ public partial struct ManualResetValueTaskSourceCore<TResult>
public short Version { get { throw null; } }
public TResult GetResult(short token) { throw null; }
public System.Threading.Tasks.Sources.ValueTaskSourceStatus GetStatus(short token) { throw null; }
public void OnCompleted(System.Action<object> continuation, object state, short token, System.Threading.Tasks.Sources.ValueTaskSourceOnCompletedFlags flags) { }
public void OnCompleted(System.Action<object?> continuation, object? state, short token, System.Threading.Tasks.Sources.ValueTaskSourceOnCompletedFlags flags) { }
public void Reset() { }
public void SetException(System.Exception error) { }
public void SetResult(TResult result) { }
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;$(NetFrameworkMinimum);netstandard2.1</TargetFrameworks>
<Nullable>disable</Nullable>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'netstandard2.1'">
<Compile Include="Microsoft.Bcl.AsyncInterfaces.cs" />
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;$(NetFrameworkMinimum);netstandard2.1</TargetFrameworks>
<Nullable>disable</Nullable>
<IsPackable>true</IsPackable>
<!-- This assembly should never be placed inbox as it is only for downlevel compatibility. -->
<PackageDescription>Provides the IAsyncEnumerable&lt;T&gt; and IAsyncDisposable interfaces and helper types for .NET Standard 2.0. This package is not required starting with .NET Standard 2.1 and .NET Core 3.0.
......
......@@ -26,22 +26,22 @@ public struct ManualResetValueTaskSourceCore<TResult>
/// or <see cref="ManualResetValueTaskSourceCoreShared.s_sentinel"/> if the operation completed before a callback was supplied,
/// or null if a callback hasn't yet been provided and the operation hasn't yet completed.
/// </summary>
private Action<object> _continuation;
private Action<object?>? _continuation;
/// <summary>State to pass to <see cref="_continuation"/>.</summary>
private object _continuationState;
private object? _continuationState;
/// <summary><see cref="ExecutionContext"/> to flow to the callback, or null if no flowing is required.</summary>
private ExecutionContext _executionContext;
private ExecutionContext? _executionContext;
/// <summary>
/// A "captured" <see cref="SynchronizationContext"/> or <see cref="TaskScheduler"/> with which to invoke the callback,
/// or null if no special context is required.
/// </summary>
private object _capturedContext;
private object? _capturedContext;
/// <summary>Whether the current operation has completed.</summary>
private bool _completed;
/// <summary>The result with which the operation succeeded, or the default value if it hasn't yet completed or failed.</summary>
private TResult _result;
private TResult? _result;
/// <summary>The exception with which the operation failed, or null if it hasn't yet completed or completed successfully.</summary>
private ExceptionDispatchInfo _error;
private ExceptionDispatchInfo? _error;
/// <summary>The current version of this value, used to help prevent misuse.</summary>
private short _version;
......@@ -105,7 +105,7 @@ public TResult GetResult(short token)
}
_error?.Throw();
return _result;
return _result!;
}
/// <summary>Schedules the continuation action for this operation.</summary>
......@@ -113,7 +113,7 @@ public TResult GetResult(short token)
/// <param name="state">The state object to pass to <paramref name="continuation"/> when it's invoked.</param>
/// <param name="token">Opaque value that was provided to the <see cref="ValueTask"/>'s constructor.</param>
/// <param name="flags">The flags describing the behavior of the continuation.</param>
public void OnCompleted(Action<object> continuation, object state, short token, ValueTaskSourceOnCompletedFlags flags)
public void OnCompleted(Action<object?> continuation, object? state, short token, ValueTaskSourceOnCompletedFlags flags)
{
if (continuation is null)
{
......@@ -128,7 +128,7 @@ public void OnCompleted(Action<object> continuation, object state, short token,
if ((flags & ValueTaskSourceOnCompletedFlags.UseSchedulingContext) != 0)
{
SynchronizationContext sc = SynchronizationContext.Current;
SynchronizationContext? sc = SynchronizationContext.Current;
if (sc != null && sc.GetType() != typeof(SynchronizationContext))
{
_capturedContext = sc;
......@@ -151,7 +151,7 @@ public void OnCompleted(Action<object> continuation, object state, short token,
// To minimize the chances of that, we check preemptively whether _continuation
// is already set to something other than the completion sentinel.
object oldContinuation = _continuation;
object? oldContinuation = _continuation;
if (oldContinuation == null)
{
_continuationState = state;
......@@ -175,7 +175,7 @@ public void OnCompleted(Action<object> continuation, object state, short token,
case SynchronizationContext sc:
sc.Post(s =>
{
var tuple = (Tuple<Action<object>, object>)s;
var tuple = (Tuple<Action<object?>, object?>)s!;
tuple.Item1(tuple.Item2);
}, Tuple.Create(continuation, state));
break;
......@@ -212,7 +212,7 @@ private void SignalCompletion()
{
ExecutionContext.Run(
_executionContext,
s => ((ManualResetValueTaskSourceCore<TResult>)s).InvokeContinuation(),
s => ((ManualResetValueTaskSourceCore<TResult>)s!).InvokeContinuation(),
this);
}
else
......@@ -247,7 +247,7 @@ private void InvokeContinuation()
case SynchronizationContext sc:
sc.Post(s =>
{
var state = (Tuple<Action<object>, object>)s;
var state = (Tuple<Action<object?>, object?>)s!;
state.Item1(state.Item2);
}, Tuple.Create(_continuation, _continuationState));
break;
......@@ -261,8 +261,8 @@ private void InvokeContinuation()
internal static class ManualResetValueTaskSourceCoreShared // separated out of generic to avoid unnecessary duplication
{
internal static readonly Action<object> s_sentinel = CompletionSentinel;
private static void CompletionSentinel(object _) // named method to aid debugging
internal static readonly Action<object?> s_sentinel = CompletionSentinel;
private static void CompletionSentinel(object? _) // named method to aid debugging
{
Debug.Fail("The sentinel delegate should never be invoked.");
throw new InvalidOperationException();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册