public void Test() { Type typeA = typeof(PropClassA); Type typeB = typeof(PropClassB); PropertyInfo pi = typeA.GetProperty("X"); MethodInfo miASet = pi.GetSetMethod(); MethodInfo miBReplace = typeB.GetMethod("PropXSetReplace"); MethodInfo miBProxy = typeB.GetMethod("PropXSetProxy"); if (miBProxy == null) { throw new Exception("PropXSetProxy is null"); } MethodHook hook = new MethodHook(miASet, miBReplace, miBProxy); hook.Install(); PropClassA a = new PropClassA(5); a.X = 7; Debug.Assert(a.X == 8); a.X = 100; Debug.Assert(a.X == 101); }
public static void PropXSetReplace(PropClassA a, int val) { Debug.LogFormat("PropXSetReplace with value:{0}", val); val += 1; PropXSetProxy(a, val); }
public void Test() { Type typeA = typeof(PropClassA); Type typeB = typeof(PropClassB); PropertyInfo pi = typeA.GetProperty("X"); MethodInfo miASet = pi.GetSetMethod(); MethodInfo miBReplace = typeB.GetMethod("PropXSetReplace"); MethodInfo miBProxy = typeB.GetMethod("PropXSetProxy"); MethodHooker hooker = new MethodHooker(miASet, miBReplace, miBProxy); hooker.Install(); PropClassA a = new PropClassA(5); a.X = 7; Debug.Assert(a.X == 8); }
public static void PropXSetProxy(PropClassA a, int val) { }