// Return the task if we were constructed from one, otherwise manufacture one. We don't
// cache the generated task into _task as it would end up changing both equality comparison
// and the hash code we generate in GetHashCode.
- _task ?? AsyncTaskMethodBuilder<TResult>.GetTaskForResult(_result);
+ _task ??
+#if netstandard
+ Task.FromResult(_result);
+#else
+ AsyncTaskMethodBuilder<TResult>.GetTaskForResult(_result);
+#endif
internal Task<TResult> AsTaskExpectNonNull() =>
// Return the task if we were constructed from one, otherwise manufacture one.
_task ?? GetTaskForResultNoInlining();
[MethodImpl(MethodImplOptions.NoInlining)]
- private Task<TResult> GetTaskForResultNoInlining() => AsyncTaskMethodBuilder<TResult>.GetTaskForResult(_result);
+ private Task<TResult> GetTaskForResultNoInlining() =>
+#if netstandard
+ Task.FromResult(_result);
+#else
+ AsyncTaskMethodBuilder<TResult>.GetTaskForResult(_result);
+#endif
/// <summary>Gets whether the <see cref="ValueTask{TResult}"/> represents a completed operation.</summary>
public bool IsCompleted => _task == null || _task.IsCompleted;
/// <summary>Gets whether the <see cref="ValueTask{TResult}"/> represents a successfully completed operation.</summary>
- public bool IsCompletedSuccessfully => _task == null || _task.IsCompletedSuccessfully;
+ public bool IsCompletedSuccessfully =>
+ _task == null ||
+#if netstandard
+ _task.Status == TaskStatus.RanToCompletion;
+#else
+ _task.IsCompletedSuccessfully;
+#endif
/// <summary>Gets whether the <see cref="ValueTask{TResult}"/> represents a failed operation.</summary>
public bool IsFaulted => _task != null && _task.IsFaulted;
/// <summary>Gets a string-representation of this <see cref="ValueTask{TResult}"/>.</summary>
public override string ToString()
{
- if (_task != null)
+ if (IsCompletedSuccessfully)
{
- return _task.IsCompletedSuccessfully && _task.Result != null ?
- _task.Result.ToString() :
- string.Empty;
- }
- else
- {
- return _result != null ?
- _result.ToString() :
- string.Empty;
+ TResult result = Result;
+ if (result != null)
+ {
+ return result.ToString();
+ }
}
+
+ return string.Empty;
}
}
}