Example #1
0
    public void Test()
    {
        MethodBase mbCtorA   = typeof(CtorHookTarget).GetConstructor(new Type[] { typeof(int) });
        MethodInfo mbReplace = new Action <int>(CtorTargetReplace).Method;
        MethodInfo mbProxy   = new Action <int>(CtorTargetProxy).Method;

        MethodHook hookder = new MethodHook(mbCtorA, mbReplace, mbProxy);

        hookder.Install();

        for (int i = 0; i < 2; i++)
        {
            CtorHookTarget hookTarget = new CtorHookTarget(1);
            Debug.Assert(hookTarget.x == 2, $"expect 2 but get {hookTarget.x} at i:{i}");
        }
    }
Example #2
0
    public void Test()
    {
        Type typeA = typeof(CtorHookTarget);
        Type typeB = typeof(CtorHookTest);

        MethodBase mbCtorA   = typeA.GetConstructor(new Type[] { typeof(int) });
        MethodBase mbReplace = typeB.GetMethod("CtorTargetReplace");
        MethodBase mbProxy   = typeB.GetMethod("CtorTargetProxy");

        MethodHook hookder = new MethodHook(mbCtorA, mbReplace, mbProxy);

        hookder.Install();

        CtorHookTarget hookTarget = new CtorHookTarget(1);

        Debug.Assert(hookTarget.x == 2);
    }