public override bool Rewrite(CodeDescriptor decompilee, MethodBase callee, StackElement[] args, IDecompiler stack, IFunctionBuilder builder) { Type returnType; if (callee.ReturnsSomething(out returnType)) throw new ArgumentException("The IgnoreOnDecompilation attribute may only be applied to methods returning a void result. Use StaticEvaluation instead."); if (_call) { callee.Invoke(args.Select(a => a.Sample).ToArray()); } return true; }
public override bool Rewrite(CodeDescriptor decompilee, MethodBase callee, StackElement[] args, IDecompiler stack, IFunctionBuilder builder) { Type returnType; if (callee.ReturnsSomething(out returnType)) { dynamic awaiter = args[0].Sample; if ((object)awaiter != null) { if (!awaiter.IsCompleted) throw new InvalidOperationException("Task not completed - what are you awaiting for?"); object resultSample = awaiter.GetResult(); var resultType = resultSample.GetType(); var fspec = new FunctionSpec(resultType) { IntrinsicRep = IntrinsicFunctions.GetAsyncResult(awaiter) }; var fcall = new FunctionCall() { Callee = fspec, Arguments = new Expression[0], ResultType = resultType }; stack.Push(fcall, resultSample); } } return true; }
public override bool Rewrite(CodeDescriptor decompilee, MethodBase callee, StackElement[] args, IDecompiler stack, IFunctionBuilder builder) { Type returnType; if (!callee.ReturnsSomething(out returnType)) throw new ArgumentException("The StaticEvaluation attribute may only be applied to methods returning some result. Use IgnoreOnDecompilation instead."); object result = null; try { result = callee.Invoke(args.Select(arg => arg.Sample).ToArray()); } catch (TargetInvocationException) { } Expression resultExpr = ResultGen(result); stack.Push(new StackElement(resultExpr, result, EVariability.Constant)); return true; }