public static void Force(T current, T branch) { MethodInfo requestMethod = current.Method; if (requestMethod.GetCustomAttribute <ILBranchableAttribute>() == null) { throw new InvalidOperationException("Methods that cannot branch at runtime"); } RuntimeBranchCompile.Br(requestMethod.MethodHandle, branch.Method.MethodHandle); }
public static void Do(T current, T true_branch, T false_branch, bool condition) { MethodInfo requestMethod = current.Method; if (requestMethod.GetCustomAttribute <ILBranchableAttribute>() == null) { throw new InvalidOperationException("Methods that cannot branch at runtime"); } MethodInfo branchTargetMethod = (condition ? true_branch : false_branch).Method; if (requestMethod.IsStatic ^ branchTargetMethod.IsStatic) { throw new InvalidOperationException("Parameters do not match"); } RuntimeBranchCompile.Br(requestMethod.MethodHandle, branchTargetMethod.MethodHandle); }
public static void Force(T current, MethodInfo info) { MethodInfo requestMethod = current.Method; if (requestMethod.GetCustomAttribute <ILBranchableAttribute>() == null) { throw new InvalidOperationException("Methods that cannot branch at runtime"); } if (info is DynamicMethod dm) { RuntimeBranchCompile.Br(requestMethod.MethodHandle, dm); } else { RuntimeBranchCompile.Br(requestMethod.MethodHandle, info.MethodHandle); } }