コード例 #1
0
 internal CallsiteSignature(Type targetType, PSMethodInvocationConstraints invocationConstraints, object[] arguments, CallsiteCacheEntryFlags flags)
 {
     this.targetType            = targetType;
     this.invocationConstraints = invocationConstraints;
     this.flags                  = flags;
     this.argumentTypes          = new Type[arguments.Length];
     this.effectiveArgumentTypes = new Type[arguments.Length];
     for (int i = 0; i < arguments.Length; i++)
     {
         this.argumentTypes[i]          = (arguments[i] == null) ? typeof(LanguagePrimitives.Null) : arguments[i].GetType();
         this.effectiveArgumentTypes[i] = Adapter.EffectiveArgumentType(arguments[i]);
     }
 }
コード例 #2
0
        private static int CompareMethods(
            Adapter.OverloadCandidate candidate1,
            Adapter.OverloadCandidate candidate2,
            object[] arguments)
        {
            ParameterInformation[] parameterInformationArray1 = candidate1.expandedParameters != null ? candidate1.expandedParameters : candidate1.parameters;
            ParameterInformation[] parameterInformationArray2 = candidate2.expandedParameters != null ? candidate2.expandedParameters : candidate2.parameters;
            int num1   = 0;
            int length = parameterInformationArray1.Length;
            int index1 = 0;

            while (index1 < parameterInformationArray1.Length)
            {
                if (candidate1.conversionRanks[index1] < candidate2.conversionRanks[index1])
                {
                    num1 -= length;
                }
                else if (candidate1.conversionRanks[index1] > candidate2.conversionRanks[index1])
                {
                    num1 += length;
                }
                else if (candidate1.conversionRanks[index1] == ConversionRank.UnrelatedArrays)
                {
                    Type           elementType     = Adapter.EffectiveArgumentType(arguments[index1]).GetElementType();
                    ConversionRank conversionRank1 = LanguagePrimitives.GetConversionRank(elementType, parameterInformationArray1[index1].parameterType.GetElementType());
                    ConversionRank conversionRank2 = LanguagePrimitives.GetConversionRank(elementType, parameterInformationArray2[index1].parameterType.GetElementType());
                    if (conversionRank1 < conversionRank2)
                    {
                        num1 -= length;
                    }
                    else if (conversionRank1 > conversionRank2)
                    {
                        num1 += length;
                    }
                }
                ++index1;
                --length;
            }
            if (num1 == 0)
            {
                int num2   = parameterInformationArray1.Length;
                int index2 = 0;
                while (index2 < parameterInformationArray1.Length)
                {
                    ConversionRank conversionRank1 = candidate1.conversionRanks[index2];
                    ConversionRank conversionRank2 = candidate2.conversionRanks[index2];
                    if (conversionRank1 >= ConversionRank.NullToValue && conversionRank2 >= ConversionRank.NullToValue && conversionRank1 >= ConversionRank.NumericImplicit == conversionRank2 >= ConversionRank.NumericImplicit)
                    {
                        if (conversionRank1 >= ConversionRank.NumericImplicit)
                        {
                            num2 = -num2;
                        }
                        ConversionRank conversionRank3 = LanguagePrimitives.GetConversionRank(parameterInformationArray1[index2].parameterType, parameterInformationArray2[index2].parameterType);
                        ConversionRank conversionRank4 = LanguagePrimitives.GetConversionRank(parameterInformationArray2[index2].parameterType, parameterInformationArray1[index2].parameterType);
                        if (conversionRank3 < conversionRank4)
                        {
                            num1 += num2;
                        }
                        else if (conversionRank3 > conversionRank4)
                        {
                            num1 -= num2;
                        }
                    }
                    ++index2;
                    num2 = Math.Abs(num2) - 1;
                }
            }
            if (num1 != 0)
            {
                return(num1);
            }
            for (int index2 = 0; index2 < parameterInformationArray1.Length; ++index2)
            {
                if (!parameterInformationArray1[index2].parameterType.Equals(parameterInformationArray2[index2].parameterType))
                {
                    return(0);
                }
            }
            if (candidate1.expandedParameters != null && candidate2.expandedParameters != null)
            {
                return(candidate1.parameters.Length <= candidate2.parameters.Length ? -1 : 1);
            }
            if (candidate1.expandedParameters != null)
            {
                return(-1);
            }
            return(candidate2.expandedParameters == null ? 0 : 1);
        }