private static DecompilationPipeline GetStateMachineRemovalPipeline(IStateMachineRemoverStep removeStateMachineStep, Func <DecompilationContext, IStateMachineData> stateMachineDataSelector) { DecompilationPipeline intermediatePipeline = BaseLanguage.IntermediateRepresenationPipeline; List <IDecompilationStep> newSteps = new List <IDecompilationStep>(); newSteps.Add(removeStateMachineStep); foreach (IDecompilationStep step in intermediatePipeline.Steps) { newSteps.Add(step); if (step is VariableAssignmentAnalysisStep) { newSteps.Add(new FieldAssignmentAnalysisStep(stateMachineDataSelector)); } } return(new DecompilationPipeline(newSteps)); }
private static BlockStatement DecompileStateMachine(this MethodBody body, MethodSpecificContext enclosingMethodContext, IStateMachineRemoverStep removeStateMachineStep, Func <DecompilationContext, IStateMachineData> stateMachineDataSelector, out DecompilationContext decompilationContext) { ILanguage language = CSharp.GetLanguage(CSharpVersion.V4); removeStateMachineStep.Language = language; DecompilationPipeline thePipeline = GetStateMachineRemovalPipeline(removeStateMachineStep, stateMachineDataSelector); decompilationContext = thePipeline.Run(body, language); enclosingMethodContext.Variables.AddRange(decompilationContext.MethodContext.Variables); enclosingMethodContext.VariableDefinitionToNameMap.AddRange(decompilationContext.MethodContext.VariableDefinitionToNameMap); enclosingMethodContext.AddInnerMethodParametersToContext(decompilationContext.MethodContext); enclosingMethodContext.VariableAssignmentData.AddRange(decompilationContext.MethodContext.VariableAssignmentData); enclosingMethodContext.GotoLabels.AddRange(decompilationContext.MethodContext.GotoLabels); enclosingMethodContext.GotoStatements.AddRange(decompilationContext.MethodContext.GotoStatements); BlockStatement theBlockStatement = thePipeline.Body; return(theBlockStatement); }