Exemplo n.º 1
0
        public static PythonType GetItem(TypeGroup self, params object[] types)
        {
            PythonType[] pythonTypes = new PythonType[types.Length];
            for (int i = 0; i < types.Length; i++)
            {
                object t = types[i];
                if (t is PythonType)
                {
                    pythonTypes[i] = (PythonType)t;
                    continue;
                }
                else if (t is TypeGroup)
                {
                    TypeGroup typeGroup = t as TypeGroup;
                    Type      nonGenericType;
                    if (!typeGroup.TryGetNonGenericType(out nonGenericType))
                    {
                        throw PythonOps.TypeError("cannot use open generic type {0} as type argument", typeGroup.Name);
                    }
                    pythonTypes[i] = DynamicHelpers.GetPythonTypeFromType(nonGenericType);
                }
                else
                {
                    throw PythonOps.TypeErrorForTypeMismatch("type", t);
                }
            }

            return(GetItemHelper(self, pythonTypes));
        }
Exemplo n.º 2
0
        public static Type ConvertToType(object value)
        {
            if (value == null)
            {
                return(null);
            }

            Type TypeVal = value as Type;

            if (TypeVal != null)
            {
                return(TypeVal);
            }

            PythonType pythonTypeVal = value as PythonType;

            if (pythonTypeVal != null)
            {
                return(pythonTypeVal.UnderlyingSystemType);
            }

            TypeGroup typeCollision = value as TypeGroup;

            if (typeCollision != null)
            {
                Type nonGenericType;
                if (typeCollision.TryGetNonGenericType(out nonGenericType))
                {
                    return(nonGenericType);
                }
            }

            throw MakeTypeError("Type", value);
        }