Exemplo n.º 1
0
        Conversion MethodGroupConversion(ResolveResult resolveResult, IType toType)
        {
            // C# 4.0 spec §6.6 Method group conversions
            MethodGroupResolveResult rr = resolveResult as MethodGroupResolveResult;

            if (rr == null)
            {
                return(Conversion.None);
            }
            IMethod m = toType.GetDelegateInvokeMethod();

            if (m == null)
            {
                return(Conversion.None);
            }

            ResolveResult[] args = new ResolveResult[m.Parameters.Count];
            for (int i = 0; i < args.Length; i++)
            {
                IParameter param         = m.Parameters[i];
                IType      parameterType = param.Type;
                if ((param.IsRef || param.IsOut) && parameterType.Kind == TypeKind.ByReference)
                {
                    parameterType = ((ByReferenceType)parameterType).ElementType;
                    args[i]       = new ByReferenceResolveResult(parameterType, param.IsOut);
                }
                else
                {
                    args[i] = new ResolveResult(parameterType);
                }
            }
            var or = rr.PerformOverloadResolution(compilation, args, allowExpandingParams: false, conversions: this);

            if (or.FoundApplicableCandidate)
            {
                IMethod method    = (IMethod)or.GetBestCandidateWithSubstitutedTypeArguments();
                var     thisRR    = rr.TargetResult as ThisResolveResult;
                bool    isVirtual = method.IsOverridable && !(thisRR != null && thisRR.CausesNonVirtualInvocation);
                return(Conversion.MethodGroupConversion(method, isVirtual));
            }
            else
            {
                return(Conversion.None);
            }
        }
Exemplo n.º 2
0
        Conversion MethodGroupConversion(ResolveResult resolveResult, IType toType)
        {
            // C# 4.0 spec §6.6 Method group conversions
            MethodGroupResolveResult rr = resolveResult as MethodGroupResolveResult;

            if (rr == null)
            {
                return(Conversion.None);
            }
            IMethod m = toType.GetDelegateInvokeMethod();

            if (m == null)
            {
                return(Conversion.None);
            }

            ResolveResult[] args = new ResolveResult[m.Parameters.Count];
            for (int i = 0; i < args.Length; i++)
            {
                IParameter param         = m.Parameters[i];
                IType      parameterType = param.Type.Resolve(context);
                if ((param.IsRef || param.IsOut) && parameterType.Kind == TypeKind.ByReference)
                {
                    parameterType = ((ByReferenceType)parameterType).ElementType;
                    args[i]       = new ByReferenceResolveResult(parameterType, param.IsOut);
                }
                else
                {
                    args[i] = new ResolveResult(parameterType);
                }
            }
            var or = rr.PerformOverloadResolution(context, args, allowExpandingParams: false);

            if (or.FoundApplicableCandidate)
            {
                return(Conversion.MethodGroupConversion((IMethod)or.BestCandidate));
            }
            else
            {
                return(Conversion.None);
            }
        }