public virtual Expression Decompile(IManagedMethod method, IList<Expression> arguments) { var elements = this.disassembler.Disassemble(method) .Select(i => (IElement)new InstructionElement(i)) .ToList(); var context = new DecompilationContext(this, method, i => arguments[i]); try { foreach (var step in this.pipeline.GetSteps()) { step.Apply(elements, context); } } catch (Exception ex) { throw new DecompilationException( "Exception while interpreting " + Environment.NewLine + ElementHelper.ToString(elements, Indent.FourSpaces) + Environment.NewLine + ex.Message, ex ); } return GetSingleExpression(elements); }
private static void ApplyPipeline(IDecompilationPipeline pipeline, IList<IElement> elements, IManagedMethod method) { var parameters = method.GetParameters().Select(p => Expression.Parameter(p.ParameterType, p.Name)).ToList(); if (!method.IsStatic) parameters.Insert(0, Expression.Parameter(method.DeclaringType, "<this>")); var context = new DecompilationContext(null, method, i => parameters[i]); foreach (var step in pipeline.GetSteps()) { step.Apply(elements, context); } }