This file contains hidden or 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
protected override void ModifyTargetMethod(MethodDefinition targetMethod) | |
{ | |
// In this example, we are going to redirect all Console.WriteLine calls | |
// to the FakeConsole.WriteLine() method | |
var module = targetMethod.Module; | |
var body = targetMethod.Body; | |
// In order to use FakeConsole.WriteLine(), we need to use Cecil to "import" | |
// the method into the modified assembly's module | |
var writeLine = module.Import(typeof (FakeConsole).GetMethod("WriteLine")); |
This file contains hidden or 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
public interface IExceptionHandlerInfo | |
{ | |
Exception Exception { get; } | |
IInvocationInfo InvocationInfo { get; } | |
object ReturnValue { get; set; } | |
bool ShouldSkipRethrow { get; set; } | |
} |
This file contains hidden or 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
public class SampleExceptionHandler : IExceptionHandler | |
{ | |
public bool CanCatch(IExceptionHandlerInfo exceptionHandlerInfo) | |
{ | |
return true; | |
} | |
public void Catch(IExceptionHandlerInfo exceptionHandlerInfo) | |
{ | |
var exception = exceptionHandlerInfo.Exception; |
This file contains hidden or 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
<PropertyGroup> | |
<PostWeaveTaskLocation>$(MSBuildProjectDirectory)\$(OutputPath)\..\..\..\lib\LinFu.Core.dll</PostWeaveTaskLocation> | |
</PropertyGroup> | |
<UsingTask TaskName="PostWeaveTask" AssemblyFile="$(PostWeaveTaskLocation)" /> | |
<Target Name="AfterBuild"> | |
<PostWeaveTask TargetFile="$(MSBuildProjectDirectory)\$(OutputPath)$(MSBuildProjectName).dll" InterceptAllExceptions="true" /> | |
</Target> |
This file contains hidden or 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using Mono.Cecil; | |
using LinFu.AOP.Interfaces; | |
using LinFu.AOP.Cecil; | |
namespace CSLInjectionDemo | |
{ |
NewerOlder