-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
231a339
commit e8bf4bc
Showing
8 changed files
with
179 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using Mono.Cecil; | ||
using Mono.Cecil.Cil; | ||
using Mono.Cecil.Rocks; | ||
using System.Linq; | ||
using static Mono.Cecil.Cil.Instruction; | ||
|
||
namespace Rougamo.Fody | ||
{ | ||
partial class ModuleWeaver | ||
{ | ||
private void StrictSyncMethodWeave(RouMethod rouMethod) | ||
{ | ||
var actualMethodDef = rouMethod.MethodDef.Clone($"$Rougamo_{rouMethod.MethodDef.Name}"); | ||
rouMethod.MethodDef.DeclaringType.Methods.Add(actualMethodDef); | ||
|
||
DebuggerStepThrough(rouMethod.MethodDef); | ||
|
||
StrictSyncAdaptedCall(rouMethod, actualMethodDef); | ||
} | ||
|
||
private void StrictSyncAdaptedCall(RouMethod rouMethod, MethodDefinition methodDef) | ||
{ | ||
var instructions = rouMethod.MethodDef.Body.Instructions; | ||
|
||
instructions.Clear(); | ||
|
||
if (!methodDef.IsStatic) instructions.Add(Create(OpCodes.Ldarg_0)); | ||
foreach(var parameter in rouMethod.MethodDef.Parameters) | ||
{ | ||
instructions.Add(Create(OpCodes.Ldarg, parameter)); | ||
} | ||
MethodReference methodRef = methodDef; | ||
if (rouMethod.MethodDef.DeclaringType.HasGenericParameters) | ||
{ | ||
var git = rouMethod.MethodDef.DeclaringType.MakeGenericInstanceType(rouMethod.MethodDef.DeclaringType.GenericParameters.Cast<TypeReference>().ToArray()); | ||
methodRef = git.GenericTypeMethodReference(methodRef, ModuleDefinition); | ||
} | ||
if (rouMethod.MethodDef.HasGenericParameters) | ||
{ | ||
methodRef = methodRef.GenericMethodReference(rouMethod.MethodDef.GenericParameters.Cast<TypeReference>().ToArray()); | ||
} | ||
instructions.Add(Create(OpCodes.Call, methodRef)); | ||
instructions.Add(Create(OpCodes.Ret)); | ||
} | ||
|
||
private void DebuggerStepThrough(MethodDefinition methodDef) | ||
{ | ||
methodDef.CustomAttributes.Clear(); | ||
methodDef.CustomAttributes.Add(new CustomAttribute(_methodDebuggerStepThroughCtorRef)); | ||
} | ||
} | ||
} |