Browse Source

Fixed async/await decompilation when the GetAwaiter() is called on a value type.

pull/344/head
Daniel Grunwald 14 years ago
parent
commit
daa5900f9c
  1. 5
      ICSharpCode.Decompiler/ILAst/AsyncDecompiler.cs
  2. 10
      ICSharpCode.Decompiler/Tests/Async.cs

5
ICSharpCode.Decompiler/ILAst/AsyncDecompiler.cs

@ -576,6 +576,11 @@ namespace ICSharpCode.Decompiler.ILAst @@ -576,6 +576,11 @@ namespace ICSharpCode.Decompiler.ILAst
if (!(getAwaiterCall.Match(ILCode.Call, out getAwaiterMethod, out awaitedExpr) || getAwaiterCall.Match(ILCode.Callvirt, out getAwaiterMethod, out awaitedExpr)))
return false;
if (awaitedExpr.Code == ILCode.AddressOf) {
// remove 'AddressOf()' when calling GetAwaiter() on a value type
awaitedExpr = awaitedExpr.Arguments[0];
}
// brtrue(IL_7C, call(valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter`1<bool>::get_IsCompleted, ldloca(CS$0$0001)))
ILLabel label;
ILExpression getIsCompletedCall;

10
ICSharpCode.Decompiler/Tests/Async.cs

@ -76,6 +76,16 @@ public class Async @@ -76,6 +76,16 @@ public class Async
}
}
public async void StreamCopyToWithConfigureAwait(Stream destination, int bufferSize)
{
byte[] array = new byte[bufferSize];
int count;
while ((count = await destination.ReadAsync(array, 0, array.Length).ConfigureAwait(false)) != 0)
{
await destination.WriteAsync(array, 0, count).ConfigureAwait(false);
}
}
public async void AwaitInLoopCondition()
{
while (await this.SimpleBoolTaskMethod())

Loading…
Cancel
Save