Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/Pose/IL/MethodRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,6 @@ private void EmitILForExceptionHandlers(ILGenerator ilGenerator, Instruction ins
ilGenerator.BeginExceptionBlock();
}

foreach (var handler in handlers.Where(h => h.HandlerStart == instruction.Offset))
{
if (handler.Flag == "Clause")
ilGenerator.BeginCatchBlock(handler.CatchType);
else if (handler.Flag == "Finally")
ilGenerator.BeginFinallyBlock();
}

foreach (var handler in handlers.Where(h => h.HandlerEnd == instruction.Offset))
{
if (handler.Flag == "Clause")
Expand All @@ -190,6 +182,14 @@ private void EmitILForExceptionHandlers(ILGenerator ilGenerator, Instruction ins

ilGenerator.EndExceptionBlock();
}

foreach (var handler in handlers.Where(h => h.HandlerStart == instruction.Offset))
{
if (handler.Flag == "Clause")
ilGenerator.BeginCatchBlock(handler.CatchType);
else if (handler.Flag == "Finally")
ilGenerator.BeginFinallyBlock();
}
}

private void EmitILForInlineNone(ILGenerator ilGenerator, Instruction instruction)
Expand Down
24 changes: 24 additions & 0 deletions test/Pose.Tests/IL/MethodRewriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,29 @@ public void TestConstructorRewrite()
Assert.AreEqual(typeof(void), dynamicMethod.ReturnType);
Assert.AreEqual(typeof(List<string>), dynamicMethod.GetParameters()[0].ParameterType);
}

[TestMethod]
public void TestExceptionHandlersRewrite()
{
MethodInfo methodInfo = typeof(MethodRewriterTests).GetMethod("ExceptionHandlersRewriteMethod");
MethodRewriter methodRewriter = MethodRewriter.CreateRewriter(methodInfo);
DynamicMethod dynamicMethod = methodRewriter.Rewrite() as DynamicMethod;

Delegate func = dynamicMethod.CreateDelegate(typeof(Func<int>));
Assert.AreEqual(1, (int)func.DynamicInvoke());
}

public static int ExceptionHandlersRewriteMethod()
{
try
{
return 1;
}
catch
{
return 0;
}
finally {}
}
}
}