public override BoundNode VisitDelegateCreationExpression(BoundDelegateCreationExpression node) { BoundSpillSequenceBuilder builder = null; var argument = VisitExpression(ref builder, node.Argument); return(UpdateExpression(builder, node.Update(argument, node.MethodOpt, node.IsExtensionMethod, node.Type))); }
public override BoundNode VisitDelegateCreationExpression(BoundDelegateCreationExpression node) { BoundExpression originalArgument = node.Argument; BoundExpression rewrittenArgument = (BoundExpression)this.Visit(originalArgument); MethodSymbol method = node.MethodOpt; if (originalArgument.Kind == BoundKind.MethodGroup && rewrittenArgument.Kind == BoundKind.MethodGroup) { // if the original argument was a method group AND the receiver was BoundKind.BaseReference // and the visited argument is still a method group with receiver overridden, change the // method to point to the wrapper method var originalReceiver = ((BoundMethodGroup)originalArgument).ReceiverOpt; var newReceiver = ((BoundMethodGroup)rewrittenArgument).ReceiverOpt; if (BaseReferenceInReceiverWasRewritten(originalReceiver, newReceiver) && method.IsMetadataVirtual()) { method = GetMethodWrapperForBaseNonVirtualCall(method, originalArgument.Syntax); // NOTE: we substitute the method in rewritten bound delegate // creation node, but leave the method group unchanged } } method = VisitMethodSymbol(method); TypeSymbol type = this.VisitType(node.Type); return(node.Update(rewrittenArgument, method, node.IsExtensionMethod, type)); }
public override BoundNode VisitDelegateCreationExpression(BoundDelegateCreationExpression node) { if (node.Argument.HasDynamicType()) { var loweredArgument = VisitExpression(node.Argument); // Creates a delegate whose instance is the delegate that is returned by the call-site and the method is Invoke. var loweredReceiver = _dynamicFactory.MakeDynamicConversion(loweredArgument, isExplicit: false, isArrayIndex: false, isChecked: false, resultType: node.Type).ToExpression(); return(new BoundDelegateCreationExpression(node.Syntax, loweredReceiver, methodOpt: null, isExtensionMethod: false, type: node.Type)); } if (node.Argument.Kind == BoundKind.MethodGroup) { var mg = (BoundMethodGroup)node.Argument; var method = node.MethodOpt; var oldSyntax = _factory.Syntax; _factory.Syntax = (mg.ReceiverOpt ?? mg).Syntax; var receiver = (method.IsStatic && !node.IsExtensionMethod) ? _factory.Type(method.ContainingType) : VisitExpression(mg.ReceiverOpt); _factory.Syntax = oldSyntax; return(node.Update(receiver, method, node.IsExtensionMethod, node.Type)); } return(base.VisitDelegateCreationExpression(node)); }
public override BoundNode VisitDelegateCreationExpression(BoundDelegateCreationExpression node) { if (node.Argument.Kind == BoundKind.MethodGroup) { var mg = (BoundMethodGroup)node.Argument; var method = node.MethodOpt; var oldSyntax = _factory.Syntax; _factory.Syntax = (mg.ReceiverOpt ?? mg).Syntax; var receiver = (method.IsStatic && !node.IsExtensionMethod) ? _factory.Type(method.ContainingType) : VisitExpression(mg.ReceiverOpt); _factory.Syntax = oldSyntax; return(node.Update(receiver, method, node.IsExtensionMethod, node.Type)); } return(base.VisitDelegateCreationExpression(node)); }
public override BoundNode VisitDelegateCreationExpression(BoundDelegateCreationExpression node) { BoundExpression originalArgument = node.Argument; BoundExpression rewrittenArgument = (BoundExpression)this.Visit(originalArgument); MethodSymbol method = node.MethodOpt; // if the original receiver was BoundKind.BaseReference (i.e. from a method group) // and the receiver is overridden, change the method to point to a wrapper method if (BaseReferenceInReceiverWasRewritten(originalArgument, rewrittenArgument) && method.IsMetadataVirtual()) { method = GetMethodWrapperForBaseNonVirtualCall(method, originalArgument.Syntax); } method = VisitMethodSymbol(method); TypeSymbol type = this.VisitType(node.Type); return node.Update(rewrittenArgument, method, node.IsExtensionMethod, type); }
public override BoundNode VisitDelegateCreationExpression(BoundDelegateCreationExpression node) { BoundExpression originalArgument = node.Argument; BoundExpression rewrittenArgument = (BoundExpression)this.Visit(originalArgument); MethodSymbol method = node.MethodOpt; if (originalArgument.Kind == BoundKind.MethodGroup && rewrittenArgument.Kind == BoundKind.MethodGroup) { // if the original argument was a method group AND the receiver was BoundKind.BaseReference // and the visited argument is still a method group with receiver overridden, change the // method to point to the wrapper method var originalReceiver = ((BoundMethodGroup)originalArgument).ReceiverOpt; var newReceiver = ((BoundMethodGroup)rewrittenArgument).ReceiverOpt; if (BaseReferenceInReceiverWasRewritten(originalReceiver, newReceiver) && method.IsMetadataVirtual()) { method = GetMethodWrapperForBaseNonVirtualCall(method, originalArgument.Syntax); // NOTE: we substitute the method in rewritten bound delegate // creation node, but leave the method group unchanged } } method = VisitMethodSymbol(method); TypeSymbol type = this.VisitType(node.Type); return node.Update(rewrittenArgument, method, node.IsExtensionMethod, type); }