ManagedHook 1.1.1

dotnet add package ManagedHook --version 1.1.1                
NuGet\Install-Package ManagedHook -Version 1.1.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ManagedHook" Version="1.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ManagedHook --version 1.1.1                
#r "nuget: ManagedHook, 1.1.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ManagedHook as a Cake Addin
#addin nuget:?package=ManagedHook&version=1.1.1

// Install ManagedHook as a Cake Tool
#tool nuget:?package=ManagedHook&version=1.1.1                

Tested with X64 architecture with non-inlined methods. (careful with optimized code with inlined methods, the pattern was not intended to be used in that case)

How to use:

1- Create a class that implements the interface IHookerHandler:

public class MyHookHandler : IHookHandler
{
    public void Before(object instanceHooked, object[] parameters)
    {
        // do whatever you want here
    }
    
    public void After(object instanceHooked, object[] parameters)
    {
        // do whatever you want here
    }
}

2- Get the methodInfo for the method to be hooked:

MethodInfo methodHooked = typeof(Foo).GetMethod("MethodHooked");

3- Hook the method!

HookManager.Instance.HookFunction(methodHooked, new MyHookHandler());

Or hook the method with lamdas (before call and after call)

HookManager.Instance.HookFunction(methodHooked, (t) => { ... }, (t) => { ... });

4 - (opt) When finished, you can unhook the method:

HookManager.Instance.UnHookFunction(methodHooked);
Product Compatible and additional computed target framework versions.
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.1 1,421 5/21/2019
1.1.0 1,087 5/21/2019
1.0.5 1,122 5/20/2019
1.0.4 1,132 5/20/2019
1.0.3 1,098 5/19/2019
1.0.2 1,097 5/19/2019
1.0.1 1,111 5/18/2019
1.0.0 1,102 5/18/2019

Use the returned value of the replaced function.