我有一个 C# dll,其成员类似于以下内容:
public void DoStuff(int i) {
try {
something.InnerDoStuff(i);
}
catch (Exception ex) {
throw ex;
}
}
我想出了如何获得throw 操作码:
Add-Type -Path 'c:\Program Files\ILSpy2\Mono.Cecil.dll'
Add-Type -Path 'c:\Program Files\ILSpy2\Mono.Cecil.pdb.dll'
$dll = 'c:\Program Files\ZippySoft\Something\foo.dll'
$assemblyDefinition = [Mono.Cecil.AssemblyDefinition]::ReadAssembly($dll);
$doThingsIlAsm = (
(
$assemblyDefinition.MainModule.Types `
| where { $_.Name -eq 'DoerOfThings' } `
| select -first 1 *
).Methods | where { $_.Name -eq 'DoStuff' }
).Body.Instructions
$throwOp = ($doThingsIlAsm | where {
$_.OpCode.Name -eq 'throw'
})
我的问题是如何将 throw opcode 替换为rethrow opcode?