/// <summary> /// Tries to safely retrieve the payload of a value task if that payload is an asynchronous task. /// If the payload is a <see cref="SystemTasks.Sources.IValueTaskSource"/>, then it returns null. /// </summary> internal static bool TryGetTask(ref SystemValueTask task, out SystemTask payload) { // Access the payload through reflection. var field = task.GetType().GetField("_obj", BindingFlags.NonPublic | BindingFlags.Instance); payload = field?.GetValueDirect(__makeref(task)) as SystemTask; return(payload != null); }
public static AsyncTypeAwaitable AsTypeAwaitable <TSource>(this ValueTask <TSource> task) { var taskTypeDescritor = AwaitableTypeDescriptor.GetTypeDescriptor(task.GetType()); return(taskTypeDescritor.GetAwaitable(task)); }