public override ICodeNode VisitLambdaExpression(LambdaExpression node)
 {
     // Visit of lambdas is needed only when locating declarations.
     if (this.state == State.LocateDeclarations)
     {
         // The following visit of the body of the lambda expression is needed, because variables that are declared in the
         // containing method, may be used in it. The clone is needed, because the lambda expression is already visited
         // and processed, and the only thing we need is to visit the variable references in it.
         Visit((node.CloneExpressionOnly() as LambdaExpression).Body);
     }
     
     return node;
 }
		public override void VisitLambdaExpression(LambdaExpression node)
		{
			if (node.IsAsync && KeyWordWriter.Async != null)
			{
				WriteKeyword(KeyWordWriter.Async);
				WriteSpace();
			}
		}
        public override void VisitLambdaExpression(LambdaExpression node)
        {
            base.VisitLambdaExpression(node);

			string lambdaMethodKeyword = node.IsFunction ? KeyWordWriter.Function : KeyWordWriter.Sub;

			WriteKeyword(lambdaMethodKeyword);
            WriteToken("(");
            VisitMethodParameters(node.Arguments);
            WriteToken(")");

			bool isShortFormLambda = false;
			bool newLineAfterStatemtentsWritten;
            if (node.Body.Statements.Count == 1)
            {
                if (node.Body.Statements[0].CodeNodeType == CodeNodeType.ExpressionStatement)
                {
					isShortFormLambda = true;
                    ShouldOmitSemicolon.Push(true);
                }
                else
                {
                    ShouldOmitSemicolon.Push(false);
                }

				if (isShortFormLambda)
				{
					WriteSpace();
				}
				else
				{
					WriteLine();
				}

                Visit(node.Body.Statements[0]);
				newLineAfterStatemtentsWritten = false;
            }
            else
            {
                ShouldOmitSemicolon.Push(false);
				WriteLine();
                Visit(node.Body);
				newLineAfterStatemtentsWritten = true;
            }

			if (!isShortFormLambda)
			{
				if (!newLineAfterStatemtentsWritten)
				{
					WriteLine();
				}

				WriteEndBlock(lambdaMethodKeyword);
			}

            ShouldOmitSemicolon.Pop();
        }
 public override ICodeNode VisitLambdaExpression(LambdaExpression node)
 {
     return node.IsExpressionTreeLambda ? node : base.VisitLambdaExpression(node);
 }
        public override void VisitLambdaExpression(LambdaExpression node)
        {
            base.VisitLambdaExpression(node);
            WriteToken("(");
            VisitMethodParameters(node.Arguments);
            WriteToken(")");
            WriteSpace();
            WriteToken("=>");
            WriteSpace();

            if (node.Body.Statements.Count == 1)
            {
                if (node.Body.Statements[0].CodeNodeType == CodeNodeType.ExpressionStatement)
                {
                    ShouldOmitSemicolon.Push(true);
                    Visit(node.Body.Statements[0] as ExpressionStatement);
                }
                else
                {
                    ShouldOmitSemicolon.Push(false);
                    Visit(node.Body);
                }
            }
            else
            {
                ShouldOmitSemicolon.Push(false);
                Visit(node.Body);
            }

            ShouldOmitSemicolon.Pop();
        }
 public override void VisitLambdaExpression(LambdaExpression node)
 {
     inLambdaCount++;
     base.VisitLambdaExpression(node);
     inLambdaCount--;
     return;
 }
            public override ICodeNode VisitObjectCreationExpression(ObjectCreationExpression node)
            {
				if (state == State.ReplaceDelegate && node.Arguments != null && node.Arguments.Count == 2 &&
                    node.Arguments[0].CodeNodeType == CodeNodeType.VariableReferenceExpression &&
                    node.Arguments[1].CodeNodeType == CodeNodeType.MethodReferenceExpression &&
                    delegateCopies.Contains((node.Arguments[0] as VariableReferenceExpression).Variable))
				{
                    //final check inserted here for optimization
                    TypeDefinition objectType = node.Constructor.DeclaringType.Resolve();
                    if (objectType == null || objectType.BaseType == null || objectType.BaseType.FullName != "System.MulticastDelegate")
                    {
                        return base.VisitObjectCreationExpression(node);
                    }

                    MethodReference methodReference = (node.Arguments[1] as MethodReferenceExpression).Method;
                    MethodDefinition methodDefinition = (node.Arguments[1] as MethodReferenceExpression).MethodDefinition;

                    MethodSpecificContext delegateMethodContext = new MethodSpecificContext(methodDefinition.Body);
                    DecompilationContext innerContext = new DecompilationContext(delegateMethodContext, context.TypeContext, context.ModuleContext, context.AssemblyContext);
                    delegateMethodContext.FieldToExpression = fieldDefToAssignedValueMap;

                    BlockStatement methodStatements = methodDefinition.Body.DecompileLambda(Language, innerContext);

					if ((methodStatements.Statements.Count == 1) && (methodStatements.Statements[0].CodeNodeType == CodeNodeType.ExpressionStatement) &&
						((methodStatements.Statements[0] as ExpressionStatement).Expression.CodeNodeType == CodeNodeType.ReturnExpression))
					{
						ReturnExpression returnExpression = (methodStatements.Statements[0] as ExpressionStatement).Expression as ReturnExpression;
						ShortFormReturnExpression shortFormReturnExpression = new ShortFormReturnExpression(returnExpression.Value, returnExpression.MappedInstructions);
						methodStatements = new BlockStatement();
						methodStatements.Statements.Add(new ExpressionStatement(shortFormReturnExpression));
					}

                    this.context.MethodContext.VariableDefinitionToNameMap.AddRange(innerContext.MethodContext.VariableDefinitionToNameMap);
					this.context.MethodContext.VariableNamesCollection.UnionWith(innerContext.MethodContext.VariableNamesCollection);
                    this.context.MethodContext.AddInnerMethodParametersToContext(innerContext.MethodContext);
					this.context.MethodContext.GotoStatements.AddRange(innerContext.MethodContext.GotoStatements);
					this.context.MethodContext.GotoLabels.AddRange(innerContext.MethodContext.GotoLabels);

                    ExpressionCollection expressionCollection = new ExpressionCollection();
                    bool hasAnonymousParamterer = LambdaExpressionsHelper.HasAnonymousParameter(methodDefinition.Parameters);
                    foreach (ParameterDefinition parameter in methodDefinition.Parameters)
                    {
                        expressionCollection.Add(new LambdaParameterExpression(parameter, !hasAnonymousParamterer, null));
                    }

                    delegatesFound.Add(methodStatements);

					LambdaExpression lambdaExpression = 
						new LambdaExpression(expressionCollection, methodStatements, methodDefinition.IsAsync(), methodDefinition.IsFunction(), methodReference.Parameters, false,
                            node.Arguments[1].MappedInstructions) { ExpressionType = objectType };

					DelegateCreationExpression result = new DelegateCreationExpression(node.Constructor.DeclaringType, lambdaExpression, node.Arguments[0], node.MappedInstructions);
					return result;
				}

                return base.VisitObjectCreationExpression(node);
            }
 public virtual void VisitLambdaExpression(LambdaExpression node)
 {
     Visit(node.Body);
 }
            private Expression ProcessReturnExpression(LambdaExpression lambdaExpression, VariableReference[] identifiers)
            {
                if (lambdaExpression.Arguments.Count != identifiers.Length || lambdaExpression.Body.Statements.Count != 1 ||
                    lambdaExpression.Body.Statements[0].CodeNodeType != CodeNodeType.ExpressionStatement)
                {
                    return null;
                }
                
                ShortFormReturnExpression returnExpression = (lambdaExpression.Body.Statements[0] as ExpressionStatement).Expression as ShortFormReturnExpression;
                if (returnExpression == null)
                {
                    return null;
                }

                Dictionary<ParameterDefinition, VariableReference> parameterToIdentifierMap = new Dictionary<ParameterDefinition, VariableReference>();
                for (int i = 0; i < identifiers.Length; i++)
                {
                    parameterToIdentifierMap[lambdaExpression.Parameters[i].Resolve()] = identifiers[i];
                }

                Expression result = returnExpression.Value.CloneAndAttachInstructions(returnExpression.MappedInstructions);
                result = (Expression)new IdentifierReplacer(parameterToIdentifierMap).Visit(result);

                return result;
            }
 public override void VisitLambdaExpression(LambdaExpression node)
 {
     if (state == SearchState.Propagation)
     {
         canBePropagated = false;
         return;
     }
     base.VisitLambdaExpression(node);
 }
 public override Expression CloneExpressionOnly()
 {
     LambdaExpression result = new LambdaExpression(Arguments.CloneExpressionsOnly(), Body.CloneStatementOnly() as BlockStatement, IsAsync, IsFunction,
         Parameters, this.IsExpressionTreeLambda, null) { ExpressionType = this.ExpressionType };
     return result;
 }