Skip to content

Commit a947a3c

Browse files
committed
.
1 parent 8c4cf67 commit a947a3c

9 files changed

Lines changed: 34 additions & 43 deletions
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
enum AsyncStateMachineKind
2+
{
3+
None,
4+
StateMachine,
5+
CompilerService
6+
}

ConfigureAwait.Fody/AttributeCleaner.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using Mono.Cecil;
2-
3-
static class AttributeCleaner
1+
static class AttributeCleaner
42
{
53
public static void Run(ModuleDefinition module)
64
{

ConfigureAwait.Fody/CecilExtensions.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
1-
using Fody;
2-
using Mono.Cecil;
3-
using Mono.Cecil.Cil;
4-
5-
enum AsyncStateMachineKind
6-
{
7-
None,
8-
StateMachine,
9-
CompilerService
10-
}
11-
12-
static class CecilExtensions
1+
static class CecilExtensions
132
{
143
// Not yet defined in Cecil, remove later when update is available.
154
const MethodImplAttributes MethodImplAttributes_Async = (MethodImplAttributes)0x2000;
@@ -22,7 +11,7 @@ public static bool IsIAsyncStateMachine(this TypeDefinition type)
2211
}
2312

2413
return type.Interfaces
25-
.Any(item => item.InterfaceType.FullName == "System.Runtime.CompilerServices.IAsyncStateMachine");
14+
.Any(_ => _.InterfaceType.FullName == "System.Runtime.CompilerServices.IAsyncStateMachine");
2615
}
2716

2817
public static MethodDefinition Method(this TypeDefinition type, MethodReference reference)
@@ -63,10 +52,14 @@ static bool IsAsyncStateMachineAttribute(this CustomAttribute attribute)
6352
public static AsyncStateMachineKind GetAsyncStateMachineKind(this MethodDefinition method)
6453
{
6554
if (method.CustomAttributes.Any(IsAsyncStateMachineAttribute))
55+
{
6656
return AsyncStateMachineKind.StateMachine;
57+
}
6758

6859
if (method.ImplAttributes.HasFlag(MethodImplAttributes_Async))
60+
{
6961
return AsyncStateMachineKind.CompilerService;
62+
}
7063

7164
return AsyncStateMachineKind.None;
7265
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Global using directives
2+
3+
global using System.Xml;
4+
global using Fody;
5+
global using Mono.Cecil;
6+
global using Mono.Cecil.Cil;
7+
global using Mono.Cecil.Rocks;

ConfigureAwait.Fody/ModuleWeaver.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
using System.Xml;
2-
using Mono.Cecil;
3-
using Mono.Cecil.Cil;
4-
using Mono.Cecil.Rocks;
5-
using Fody;
6-
7-
public partial class ModuleWeaver : BaseModuleWeaver
1+
public partial class ModuleWeaver : BaseModuleWeaver
82
{
93
public override void Execute()
104
{
@@ -181,7 +175,9 @@ void TryRedirectMethodInstruction(MethodReference method, Instruction instructio
181175
{
182176
// Only redirect GetAwaiter; other members (including constructors) must not be redirected
183177
if (method.Name != "GetAwaiter")
178+
{
184179
return;
180+
}
185181

186182
var newOperand = genericConfiguredTaskAwaitableTypeDef.Method(method);
187183
if (newOperand != null)
@@ -200,7 +196,9 @@ void TryRedirectMethodInstruction(MethodReference method, Instruction instructio
200196
{
201197
// Only redirect GetAwaiter; other members (including constructors) must not be redirected
202198
if (method.Name != "GetAwaiter")
199+
{
203200
return;
201+
}
204202

205203
var newOperand = genericConfiguredValueTaskAwaitableTypeDef.Method(method);
206204
if (newOperand != null)

ConfigureAwait.Fody/ModuleWeaver_CompilerServices.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using Fody;
2-
using Mono.Cecil;
3-
using Mono.Cecil.Cil;
4-
using Mono.Cecil.Rocks;
5-
6-
public partial class ModuleWeaver
1+
public partial class ModuleWeaver
72
{
83
/// <summary>
94
/// Rewrites calls to <c>System.Runtime.CompilerServices.AsyncHelpers.Await(task)</c> inside
@@ -179,9 +174,10 @@ void AddAwaitConfigToAsyncMethod(MethodDefinition method, bool configureAwaitVal
179174

180175
static MethodDefinition FindAwaitMethodDefinition(TypeDefinition declaringType, string configuredAwaitableName)
181176
{
182-
return declaringType.Methods.FirstOrDefault(m =>
183-
m.Name == "Await" &&
184-
m.Parameters.Count == 1 &&
185-
m.Parameters[0].ParameterType.Name == configuredAwaitableName) ?? throw new WeavingException($"Failed to find target method: Await({configuredAwaitableName})");
177+
return declaringType.Methods
178+
.FirstOrDefault(_ =>
179+
_.Name == "Await" &&
180+
_.Parameters.Count == 1 &&
181+
_.Parameters[0].ParameterType.Name == configuredAwaitableName) ?? throw new WeavingException($"Failed to find target method: Await({configuredAwaitableName})");
186182
}
187183
}

ConfigureAwait.Fody/ModuleWeaver_Fields.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using Mono.Cecil;
2-
3-
public partial class ModuleWeaver
1+
public partial class ModuleWeaver
42
{
53
void ProcessFields(TypeDefinition type)
64
{

ConfigureAwait.Fody/ModuleWeaver_TypeFinder.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using Mono.Cecil;
2-
3-
public partial class ModuleWeaver
1+
public partial class ModuleWeaver
42
{
53
TypeReference configuredTaskAwaitableTypeRef;
64
TypeReference configuredValueTaskAwaitableTypeRef;

ConfigureAwait.Fody/ModuleWeaver_Variables.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using Mono.Cecil;
2-
using Mono.Cecil.Cil;
3-
4-
public partial class ModuleWeaver
1+
public partial class ModuleWeaver
52
{
63
void ProcessVariables(bool configureAwaitValue, MethodDefinition method)
74
{

0 commit comments

Comments
 (0)