Esempio n. 1
0
 static void InitTypeParameters(IKVM.Reflection.Type typeDefinition, ICollection<IUnresolvedTypeParameter> typeParameters)
 {
     // Type parameters are initialized within the constructor so that the class can be put into the type storage
     // before the rest of the initialization runs - this allows it to be available for early binding as soon as possible.
     var genericArguments = typeDefinition.GetGenericArguments ();
     for (int i = 0; i < genericArguments.Length; i++) {
         if (genericArguments[i].GenericParameterPosition != i)
             throw new InvalidOperationException("g.GenericParameterPosition != i");
         typeParameters.Add(new DefaultUnresolvedTypeParameter(
             EntityType.TypeDefinition, i, genericArguments [i].Name));
     }
 }
Esempio n. 2
0
        ITypeReference CreateTypeReference(IKVM.Reflection.Type type, IEnumerable<CustomAttributeData> typeAttributes, ref int typeIndex)
        {
            // TODO:
            //			while (type is OptionalModifierType || type is RequiredModifierType) {
            //				type = ((TypeSpecification)type).ElementType;
            //			}

            if (type == null) {
                return SpecialType.UnknownType;
            }

            if (type.IsByRef) {
                typeIndex++;
                return interningProvider.Intern (
                    new ByReferenceTypeReference (
                    CreateTypeReference (
                    type.GetElementType (),
                    typeAttributes, ref typeIndex)));
            }
            if (type.IsPointer) {
                typeIndex++;
                return interningProvider.Intern (
                    new PointerTypeReference (
                    CreateTypeReference (
                    type.GetElementType (),
                    typeAttributes, ref typeIndex)));
            }
            if (type.IsArray) {
                typeIndex++;
                return interningProvider.Intern (
                    new ArrayTypeReference (
                        CreateTypeReference (
                        type.GetElementType (),
                        typeAttributes, ref typeIndex),
                        type.GetArrayRank ()));
            }
            if (type.IsConstructedGenericType) {
                ITypeReference baseType = CreateTypeReference (type.GetGenericTypeDefinition (), typeAttributes, ref typeIndex);
                var args = type.GetGenericArguments ();
                var para = new ITypeReference[args.Length];
                for (int i = 0; i < para.Length; ++i) {
                    typeIndex++;
                    para [i] = CreateTypeReference (args [i], typeAttributes, ref typeIndex);
                }
                return interningProvider.Intern (new ParameterizedTypeReference (baseType, para));
            }
            if (type.IsGenericParameter) {
                return TypeParameterReference.Create (type.DeclaringMethod != null ? EntityType.Method : EntityType.TypeDefinition, type.GenericParameterPosition);
            }
            if (type.IsNested) {
                ITypeReference typeRef = CreateTypeReference (type.DeclaringType, typeAttributes, ref typeIndex);
                int partTypeParameterCount;
                string namepart = ReflectionHelper.SplitTypeParameterCountFromReflectionName (type.Name, out partTypeParameterCount);
                namepart = interningProvider.Intern (namepart);
                return interningProvider.Intern (new NestedTypeReference (typeRef, namepart, partTypeParameterCount));
            }

            string ns = interningProvider.Intern (type.Namespace ?? string.Empty);
            string name = type.Name;
            if (name == null)
                throw new InvalidOperationException ("type.Name returned null. Type: " + type);

            if (name == "Object" && ns == "System" && HasDynamicAttribute (typeAttributes, typeIndex)) {
                return SpecialType.Dynamic;
            }
            int typeParameterCount;
            name = ReflectionHelper.SplitTypeParameterCountFromReflectionName (name, out typeParameterCount);
            name = interningProvider.Intern (name);
            if (currentAssembly != null) {
                IUnresolvedTypeDefinition c = currentAssembly.GetTypeDefinition (ns, name, typeParameterCount);
                if (c != null)
                    return c;
            }
            return interningProvider.Intern (new GetClassTypeReference (GetAssemblyReference (type.Assembly), ns, name, typeParameterCount));
        }
Esempio n. 3
0
 void InitTypeParameterConstraints(IKVM.Reflection.Type typeDefinition, IList<IUnresolvedTypeParameter> typeParameters)
 {
     var args = typeDefinition.GetGenericArguments ();
     for (int i = 0; i < typeParameters.Count; i++) {
         var tp = (DefaultUnresolvedTypeParameter)typeParameters[i];
         AddConstraints(tp, args[i]);
         tp.ApplyInterningProvider(interningProvider);
     }
 }
Esempio n. 4
0
 internal static IKVM.Reflection.Type GetUnderlyingType(IKVM.Reflection.Type type)
 {
     if (type.IsValueType && type.IsGenericType && type.GetGenericTypeDefinition().FullName == "System.Nullable`1")
     {
         return type.GetGenericArguments()[0];
     }
     return null;
 }