public override bool Rewrite(CodeDescriptor decompilee, MethodBase callee, StackElement[] args, IDecompiler stack, IFunctionBuilder builder) { if (args[0].Variability == Msil.EVariability.ExternVariable) { throw new NotSupportedException("Delegate calls must have constant target!"); } Delegate deleg = (Delegate)args[0].Sample; if (deleg == null) { return(false); } StackElement[] callArgs; if (deleg.Method.IsStatic) { callArgs = new StackElement[args.Length - 1]; Array.Copy(args, 1, callArgs, 0, args.Length - 1); } else { callArgs = new StackElement[args.Length]; Array.Copy(args, callArgs, args.Length); callArgs[0].Sample = deleg.Target; callArgs[0].Expr = LiteralReference.CreateConstant(deleg.Target); callArgs[0].Variability = Msil.EVariability.Constant; } stack.ImplementCall(deleg.Method, callArgs); return(true); }
public override bool Rewrite(CodeDescriptor decompilee, MethodBase callee, StackElement[] args, IDecompiler stack, IFunctionBuilder builder) { if (args[0].Variability == Msil.EVariability.ExternVariable) throw new NotSupportedException("Delegate calls must have constant target!"); Delegate deleg = (Delegate)args[0].Sample; if (deleg == null) return false; StackElement[] callArgs; if (deleg.Method.IsStatic) { callArgs = new StackElement[args.Length - 1]; Array.Copy(args, 1, callArgs, 0, args.Length - 1); } else { callArgs = new StackElement[args.Length]; Array.Copy(args, callArgs, args.Length); callArgs[0].Sample = deleg.Target; callArgs[0].Expr = LiteralReference.CreateConstant(deleg.Target); callArgs[0].Variability = Msil.EVariability.Constant; } stack.ImplementCall(deleg.Method, callArgs); return true; }