private bool Match() { if (this.originalStatements.get_Count() == 0) { return(false); } if (!this.methodContext.get_Method().IsAsync(out this.stateMachineTypeDef) && !this.methodContext.get_Method().HasAsyncAttributes() || !this.IsAsyncFirstAssignmentStatement(this.originalStatements.get_Item(0), out this.stateMachineTypeDef) || !this.methodContext.get_Method().HasAsyncStateMachineVariable()) { return(false); } if (!this.GetBuilderField()) { return(false); } this.asyncStatements = this.GetMoveNextStatements(); if (this.asyncStatements == null || !this.TryRemoveOuterTryCatch(this.asyncStatements)) { return(false); } this.SetParameterMappings(this.originalStatements); this.matcherState = 0; this.asyncStatements = (StatementCollection)this.Visit(this.asyncStatements); if (this.matcherState == RebuildAsyncStatementsStep.MatcherState.FindAwaitExpression) { return(true); } return(this.matcherState == 4); }
public override ICodeNode VisitBinaryExpression(BinaryExpression node) { if (node.get_Operator() == 26) { if (node.get_Left().get_CodeNodeType() == 26 && this.asyncData.get_AwaiterVariables().Contains((node.get_Left() as VariableReferenceExpression).get_Variable())) { V_0 = (node.get_Left() as VariableReferenceExpression).get_Variable(); if (node.get_Right().get_CodeNodeType() != 19 || !String.op_Equality((node.get_Right() as MethodInvocationExpression).get_MethodExpression().get_Method().get_Name(), "GetAwaiter")) { if (node.get_Right().get_CodeNodeType() == 40 || node.get_Right().get_CodeNodeType() == 22 && (node.get_Right() as LiteralExpression).get_Value() == null && this.matcherState & 4 == 4 && (object)this.currentAwaiterVariable == (object)V_0) { this.matcherState = this.matcherState ^ 4; return(null); } } else { V_1 = null; V_2 = node.get_Right() as MethodInvocationExpression; if (V_2.get_MethodExpression().get_Target() == null) { if (V_2.get_Arguments().get_Count() == 1) { V_1 = (Expression)this.Visit(V_2.get_Arguments().get_Item(0)); } } else { if (V_2.get_Arguments().get_Count() == 0) { V_1 = (Expression)this.Visit(V_2.get_MethodExpression().get_Target()); } } if (V_1 != null && this.matcherState == RebuildAsyncStatementsStep.MatcherState.FindAwaitExpression || this.matcherState == 4) { this.currentAwaiterVariable = V_0; this.awaitedExpression = V_1; this.matcherState = 1; return(null); } } this.matcherState = 8; return(node); } if (node.get_Left().get_CodeNodeType() == 30 && (object)(node.get_Left() as FieldReferenceExpression).get_Field().Resolve() == (object)this.asyncData.get_StateField() || node.get_Right().get_CodeNodeType() == 28) { return(null); } } return(this.VisitBinaryExpression(node)); }
public override ICodeNode VisitPropertyReferenceExpression(PropertyReferenceExpression node) { V_0 = node.get_MethodExpression(); if (V_0.get_Target() == null || V_0.get_Target().get_CodeNodeType() != 26 || !this.asyncData.get_AwaiterVariables().Contains((V_0.get_Target() as VariableReferenceExpression).get_Variable())) { return(this.VisitPropertyReferenceExpression(node)); } V_1 = (V_0.get_Target() as VariableReferenceExpression).get_Variable(); if ((object)this.currentAwaiterVariable == (object)V_1 && String.op_Equality(V_0.get_Method().get_Name(), "get_IsCompleted") && this.matcherState == 1) { this.matcherState = 6; return(null); } this.matcherState = 8; return(node); }
public override ICodeNode VisitMethodInvocationExpression(MethodInvocationExpression node) { V_0 = node.get_MethodExpression(); if (V_0.get_Target() != null) { if (V_0.get_Target().get_CodeNodeType() == 26 && this.asyncData.get_AwaiterVariables().Contains((V_0.get_Target() as VariableReferenceExpression).get_Variable())) { V_1 = (V_0.get_Target() as VariableReferenceExpression).get_Variable(); if ((object)this.currentAwaiterVariable == (object)V_1) { if (!String.op_Equality(V_0.get_Method().get_Name(), "get_IsCompleted")) { if (String.op_Equality(V_0.get_Method().get_Name(), "GetResult") && this.matcherState & 2 == 2) { this.matcherState = this.matcherState ^ 2; return(new AwaitExpression((Expression)this.Visit(this.awaitedExpression), V_0.get_Method().get_ReturnType(), node.get_UnderlyingSameMethodInstructions())); } } else { if (this.matcherState == 1) { this.matcherState = 6; return(null); } } } this.matcherState = 8; return(node); } if (V_0.get_Target().get_CodeNodeType() == 30 && (object)(V_0.get_Target() as FieldReferenceExpression).get_Field().Resolve() == (object)this.builderField && String.op_Equality(V_0.get_Method().get_Name(), "SetResult")) { if (node.get_Arguments().get_Count() > 0) { stackVariable34 = node.get_Arguments().get_Item(0); } else { stackVariable34 = null; } return(new ReturnExpression(stackVariable34, V_0.get_UnderlyingSameMethodInstructions())); } } return(this.VisitMethodInvocationExpression(node)); }