GetTypes() protected static method

protected static GetTypes ( Operand ops, ITypeMapper typeMapper ) : Type[]
ops Operand
typeMapper ITypeMapper
return Type[]
Ejemplo n.º 1
0
        public static ApplicableFunction ValidateCandidate(IMemberInfo candidate, Operand[] args, ITypeMapper typeMapper)
        {
            Type[] cTypes = candidate.ParameterTypes;

            if (cTypes.Length == args.Length)
            {
                Conversion[] conversions = new Conversion[args.Length];

                for (int i = 0; i < cTypes.Length; i++)
                {
                    conversions[i] = Conversion.GetImplicit(args[i], cTypes[i], false, typeMapper);
                    if (!conversions[i].IsValid)
                    {
                        if (cTypes[i].IsByRef)
                        {
                            conversions[i] = Conversion.GetImplicit(args[i], cTypes[i].GetElementType(), false, typeMapper);
                        }
                        if (!conversions[i].IsValid)
                        {
                            return(null);
                        }
                    }
                }

                return(new ApplicableFunction(candidate, cTypes, cTypes, Operand.GetTypes(args, typeMapper), conversions));
            }

            if (candidate.IsParameterArray && args.Length >= cTypes.Length - 1)
            {
                Type[] expandedTypes = new Type[args.Length];
                Array.Copy(cTypes, expandedTypes, cTypes.Length - 1);
                Type varType = cTypes[cTypes.Length - 1].GetElementType();

                for (int i = cTypes.Length - 1; i < expandedTypes.Length; i++)
                {
                    expandedTypes[i] = varType;
                }

                Conversion[] conversions = new Conversion[args.Length];

                for (int i = 0; i < expandedTypes.Length; i++)
                {
                    conversions[i] = Conversion.GetImplicit(args[i], expandedTypes[i], false, typeMapper);
                    if (!conversions[i].IsValid)
                    {
                        return(null);
                    }
                }

                return(new ApplicableFunction(candidate, cTypes, expandedTypes, Operand.GetTypes(args, typeMapper), conversions));
            }

            return(null);
        }
Ejemplo n.º 2
0
        public static ApplicableFunction ValidateCandidate(IMemberInfo candidate, Operand[] args)
        {
            Type[] cTypes = candidate.ParameterTypes;

            bool breaking = false;

            if (cTypes.Length == args.Length)
            {
                Conversion[] conversions = new Conversion[args.Length];

                for (int i = 0; i < cTypes.Length; i++)
                {
                    conversions[i] = Conversion.GetImplicit(args[i], cTypes[i], false);
                    if (!conversions[i].IsValid && !cTypes[i].IsGenericParameter)
                    {
                        breaking = true;
                        break;
                    }
                }
                if (!breaking)
                {
                    return(new ApplicableFunction(candidate, cTypes, cTypes, Operand.GetTypes(args), conversions));
                }
            }

            if (candidate.IsParameterArray && args.Length >= cTypes.Length - 1)
            {
                Type[] expandedTypes = new Type[args.Length];
                Array.Copy(cTypes, expandedTypes, cTypes.Length - 1);
                Type varType = cTypes[cTypes.Length - 1].GetElementType();

                for (int i = cTypes.Length - 1; i < expandedTypes.Length; i++)
                {
                    expandedTypes[i] = varType;
                }

                Conversion[] conversions = new Conversion[args.Length];

                for (int i = 0; i < expandedTypes.Length; i++)
                {
                    conversions[i] = Conversion.GetImplicit(args[i], expandedTypes[i], false);
                    if (!conversions[i].IsValid)
                    {
                        return(null);
                    }
                }

                return(new ApplicableFunction(candidate, cTypes, expandedTypes, Operand.GetTypes(args), conversions));
            }

            return(null);
        }