Skip to content

Instantly share code, notes, and snippets.

@kevingosse
Created February 1, 2019 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevingosse/b0f787e73a96bcda8dec610780cbe2e7 to your computer and use it in GitHub Desktop.
Save kevingosse/b0f787e73a96bcda8dec610780cbe2e7 to your computer and use it in GitHub Desktop.
private void MutateState(Task task)
{
var continuationWrapperType = Type.GetType("System.Runtime.CompilerServices.AsyncMethodBuilderCore+ContinuationWrapper");
var taskAction = typeof(Task).GetField("m_action", BindingFlags.Instance | BindingFlags.NonPublic)
.GetValue(task);
Delegate func = task.AsyncState as Delegate ?? taskAction as Delegate;
if (func?.Target?.GetType() == continuationWrapperType)
{
var continuationWrapper = func.Target;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment