private BoundNode RewriteMethodGroupConversion(BoundConversion conversion)
        {
            // in a method group conversion, we may need to rewrite the selected method
            BoundMethodGroup operand             = (BoundMethodGroup)conversion.Operand;
            BoundExpression  originalReceiverOpt = operand.ReceiverOpt;
            BoundExpression  receiverOpt;

            if (originalReceiverOpt == null)
            {
                receiverOpt = null;
            }
            else if (!conversion.IsExtensionMethod && conversion.SymbolOpt.IsStatic)
            {
                receiverOpt = new BoundTypeExpression(originalReceiverOpt.Syntax, null, VisitType(originalReceiverOpt.Type));
            }
            else
            {
                receiverOpt = (BoundExpression)Visit(originalReceiverOpt);
            }

            TypeSymbol type = this.VisitType(conversion.Type);

            MethodSymbol method = conversion.SymbolOpt;

            //  if the original receiver was a base access and is was rewritten,
            //  change the method to point to the wrapper method
            if (BaseReferenceInReceiverWasRewritten(originalReceiverOpt, receiverOpt) && method.IsMetadataVirtual())
            {
                method = GetMethodWrapperForBaseNonVirtualCall(method, conversion.Syntax);
            }

            method  = VisitMethodSymbol(method);
            operand = operand.Update(
                TypeMap.SubstituteTypesWithoutModifiers(operand.TypeArgumentsOpt),
                method.Name,
                operand.Methods,
                operand.LookupSymbolOpt,
                operand.LookupError,
                operand.Flags,
                receiverOpt,
                operand.ResultKind);

            var conversionInfo = conversion.Conversion;

            if (conversionInfo.Method != (object)method)
            {
                conversionInfo = conversionInfo.SetConversionMethod(method);
            }

            return(conversion.Update(
                       operand,
                       conversionInfo,
                       isBaseConversion: conversion.IsBaseConversion,
                       @checked: conversion.Checked,
                       explicitCastInCode: conversion.ExplicitCastInCode,
                       constantValueOpt: conversion.ConstantValueOpt,
                       type: type));
        }
Example #2
0
 public override BoundNode VisitMethodGroup(BoundMethodGroup node)
 {
     if ((node.Flags & BoundMethodGroupFlags.HasImplicitReceiver) == BoundMethodGroupFlags.HasImplicitReceiver &&
         (object)_targetMethodThisParameter == null)
     {
         // This can happen in static contexts.
         // NOTE: LocalRewriter has already been run, so the receiver has already been replaced with an
         // appropriate type expression, if this is a static context.
         // NOTE: Don't go through VisitThisReference, because it'll produce a diagnostic.
         return(node.Update(
                    node.TypeArgumentsOpt,
                    node.Name,
                    node.Methods,
                    node.LookupSymbolOpt,
                    node.LookupError,
                    node.Flags,
                    receiverOpt: null,
                    resultKind: node.ResultKind));
     }
     else
     {
         return(base.VisitMethodGroup(node));
     }
 }
 public override BoundNode VisitMethodGroup(BoundMethodGroup node)
 {
     if ((node.Flags & BoundMethodGroupFlags.HasImplicitReceiver) == BoundMethodGroupFlags.HasImplicitReceiver &&
         (object)_targetMethodThisParameter == null)
     {
         // This can happen in static contexts.
         // NOTE: LocalRewriter has already been run, so the receiver has already been replaced with an
         // appropriate type expression, if this is a static context.
         // NOTE: Don't go through VisitThisReference, because it'll produce a diagnostic.
         return node.Update(
             node.TypeArgumentsOpt,
             node.Name,
             node.Methods,
             node.LookupSymbolOpt,
             node.LookupError,
             node.Flags,
             receiverOpt: null,
             resultKind: node.ResultKind);
     }
     else
     {
         return base.VisitMethodGroup(node);
     }
 }