public override Expression CloneExpressionOnly() { DelegateCreationExpression result = new DelegateCreationExpression(Type, MethodExpression.CloneExpressionOnly(), Target.CloneExpressionOnly(), null); result.TypeIsImplicitlyInferable = this.TypeIsImplicitlyInferable; return(result); }
public DelegateCreationExpression(TypeReference type, Expression method, Expression target, IEnumerable <Instruction> instructions) { base(instructions); this.set_Type(type); this.set_MethodExpression(method); this.set_Target(target); this.set_TypeIsImplicitlyInferable(DelegateCreationExpression.ContainsAnonymousType(type)); return; }
public override bool Equals(Expression other) { if (!(other is DelegateCreationExpression)) { return(false); } DelegateCreationExpression delegateCreation = other as DelegateCreationExpression; #region TargetsComparison if (this.Target == null) { if (delegateCreation.Target != null) { return(false); } } else if (!this.Target.Equals(delegateCreation.Target)) { return(false); } #endregion #region MethodComparison if (!this.MethodExpression.Equals(delegateCreation.MethodExpression)) { return(false); } #endregion #region TypeComparison return(this.Type.FullName == delegateCreation.Type.FullName); #endregion }
public override void VisitDelegateCreationExpression(DelegateCreationExpression node) { if (!node.TypeIsImplicitlyInferable) { WriteKeyword(KeyWordWriter.New); WriteSpace(); WriteReference(node.Type); Write("("); } if (node.MethodExpression.CodeNodeType != CodeNodeType.LambdaExpression) { Write(node.Target); Write("."); } Write(node.MethodExpression); if (!node.TypeIsImplicitlyInferable) { Write(")"); } }
public override Expression CloneExpressionOnly() { DelegateCreationExpression result = new DelegateCreationExpression(Type, MethodExpression.CloneExpressionOnly(), Target.CloneExpressionOnly(), null); result.TypeIsImplicitlyInferable = this.TypeIsImplicitlyInferable; return result; }
public override void VisitDelegateCreationExpression(DelegateCreationExpression node) { if (node.MethodExpression.CodeNodeType == CodeNodeType.LambdaExpression) { VisitLambdaExpression((LambdaExpression)node.MethodExpression); } else { base.VisitDelegateCreationExpression(node); } }
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 VisitDelegateCreationExpression(DelegateCreationExpression node) { Visit(node.Target); Visit(node.MethodExpression); }
public override Expression CloneExpressionOnly() { stackVariable9 = new DelegateCreationExpression(this.get_Type(), this.get_MethodExpression().CloneExpressionOnly(), this.get_Target().CloneExpressionOnly(), null); stackVariable9.set_TypeIsImplicitlyInferable(this.get_TypeIsImplicitlyInferable()); return(stackVariable9); }
public override Expression Clone() { stackVariable10 = new DelegateCreationExpression(this.get_Type(), this.get_MethodExpression().Clone(), this.get_Target().Clone(), this.instructions); stackVariable10.set_TypeIsImplicitlyInferable(this.get_TypeIsImplicitlyInferable()); return(stackVariable10); }
public override void VisitDelegateCreationExpression(DelegateCreationExpression node) { if (state == SearchState.Propagation) { canBePropagated = false; return; } base.VisitDelegateCreationExpression(node); }