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 override void VisitDelegateCreationExpression(DelegateCreationExpression node) { if (state == SearchState.Propagation) { canBePropagated = false; return; } base.VisitDelegateCreationExpression(node); }
public override void VisitDelegateCreationExpression(DelegateCreationExpression node) { if (node.MethodExpression.CodeNodeType == CodeNodeType.LambdaExpression) { VisitLambdaExpression((LambdaExpression)node.MethodExpression); return; } base.VisitDelegateCreationExpression(node); }
public override void VisitDelegateCreationExpression(DelegateCreationExpression node) { if (node.get_MethodExpression().get_CodeNodeType() != 50) { this.VisitDelegateCreationExpression(node); return; } this.VisitLambdaExpression((LambdaExpression)node.get_MethodExpression()); return; }
public override void VisitDelegateCreationExpression(DelegateCreationExpression node) { if (this.state == ExpressionPropagationStep.ExpressionTreeVisitor.SearchState.Propagation) { this.canBePropagated = false; return; } this.VisitDelegateCreationExpression(node); return; }
private void TraverseMethodParameters(MethodReference method, ExpressionCollection arguments) { for (int i = 0; i < method.Parameters.Count; i++) { if (arguments[i].CodeNodeType == CodeNodeType.DelegateCreationExpression) { DelegateCreationExpression theDelegateCreation = (DelegateCreationExpression)arguments[i]; ParameterDefinition parameter = method.Parameters[i]; if (CanInferTypeOfDelegateCreation(parameter.ParameterType)) { theDelegateCreation.TypeIsImplicitlyInferable = true; } } } }
private LambdaExpression GetLambdaExpression(Expression expression, bool queryable) { if (queryable) { LambdaExpression lambdaExpression = expression as LambdaExpression; return(lambdaExpression != null && lambdaExpression.IsExpressionTreeLambda ? lambdaExpression : null); } DelegateCreationExpression delegateCreation = expression as DelegateCreationExpression; if (delegateCreation != null && delegateCreation.MethodExpression.CodeNodeType == CodeNodeType.LambdaExpression) { return(delegateCreation.MethodExpression as LambdaExpression); } return(null); }
public override void VisitBinaryExpression(BinaryExpression node) { base.VisitBinaryExpression(node); if (node.IsAssignmentExpression && node.Right.CodeNodeType == CodeNodeType.DelegateCreationExpression) { DelegateCreationExpression theDelegateCreation = (DelegateCreationExpression)node.Right; if (node.Left.HasType) { TypeReference leftType = node.Left.ExpressionType; if (CanInferTypeOfDelegateCreation(leftType)) { theDelegateCreation.TypeIsImplicitlyInferable = true; } } } }
public override void VisitReturnExpression(ReturnExpression node) { base.VisitReturnExpression(node); if (node.Value == null) { return; } if (node.Value.CodeNodeType == CodeNodeType.DelegateCreationExpression) { DelegateCreationExpression theDelegate = (DelegateCreationExpression)node.Value; TypeReference returnType = context.MethodContext.Method.ReturnType; if (CanInferTypeOfDelegateCreation(returnType)) { theDelegate.TypeIsImplicitlyInferable = true; } } }
public virtual void VisitDelegateCreationExpression(DelegateCreationExpression node) { Visit(node.Target); Visit(node.MethodExpression); }
public virtual ICodeNode VisitDelegateCreationExpression(DelegateCreationExpression node) { node.Target = (Expression)Visit(node.Target); node.MethodExpression = (Expression)Visit(node.MethodExpression); return(node); }
public virtual void VisitDelegateCreationExpression(DelegateCreationExpression node) { this.Visit(node.get_Target()); this.Visit(node.get_MethodExpression()); return; }
public virtual ICodeNode VisitDelegateCreationExpression(DelegateCreationExpression node) { node.set_Target((Expression)this.Visit(node.get_Target())); node.set_MethodExpression((Expression)this.Visit(node.get_MethodExpression())); return(node); }