Esempio n. 1
0
        public static TypeVariableReference CreateTypeVariableReferenceFromNIType(
            this TypeVariableSet typeVariableSet,
            NIType type,
            Dictionary <NIType, TypeVariableReference> genericTypeParameters)
        {
            if (type.IsGenericParameter())
            {
                return(genericTypeParameters[type]);
            }

            if (type.IsInterface())
            {
                return(typeVariableSet.CreateTypeVariableReferenceFromInterfaceNIType(type, genericTypeParameters));
            }

            if (type.IsCluster())
            {
                TypeVariableReference[] elementTypes = type.GetFields()
                                                       .Select(t => typeVariableSet.CreateTypeVariableReferenceFromNIType(t.GetDataType(), genericTypeParameters))
                                                       .ToArray();
                return(typeVariableSet.CreateReferenceToTupleType(elementTypes));
            }

            if (!type.IsClass() && !type.IsUnion())
            {
                return(typeVariableSet.CreateTypeVariableReferenceFromPrimitiveType(type, genericTypeParameters));
            }

            if (type.IsRebarReferenceType())
            {
                TypeVariableReference referentType = typeVariableSet.CreateTypeVariableReferenceFromNIType(type.GetReferentType(), genericTypeParameters);
                TypeVariableReference lifetimeType = typeVariableSet.CreateTypeVariableReferenceFromNIType(type.GetReferenceLifetimeType(), genericTypeParameters);
                if (type.IsPolymorphicReferenceType())
                {
                    TypeVariableReference mutabilityType = typeVariableSet.CreateTypeVariableReferenceFromNIType(type.GetReferenceMutabilityType(), genericTypeParameters);
                    return(typeVariableSet.CreateReferenceToPolymorphicReferenceType(mutabilityType, referentType, lifetimeType));
                }
                return(typeVariableSet.CreateReferenceToReferenceType(type.IsMutableReferenceType(), referentType, lifetimeType));
            }

            return(typeVariableSet.CreateTypeVariableReferenceFromClassOrUnionNIType(type, genericTypeParameters));
        }
Esempio n. 2
0
 public static TypeVariableReference CreateTypeVariableReferenceFromNIType(
     this TypeVariableSet typeVariableSet,
     NIType type,
     Dictionary <NIType, TypeVariableReference> genericTypeParameters)
 {
     if (type.IsGenericParameter())
     {
         return(genericTypeParameters[type]);
     }
     else if (!type.IsGenericType())
     {
         return(typeVariableSet.CreateReferenceToLiteralType(type));
     }
     else
     {
         if (type.IsRebarReferenceType())
         {
             TypeVariableReference referentType = typeVariableSet.CreateTypeVariableReferenceFromNIType(type.GetReferentType(), genericTypeParameters);
             TypeVariableReference lifetimeType = typeVariableSet.CreateTypeVariableReferenceFromNIType(type.GetReferenceLifetimeType(), genericTypeParameters);
             if (type.IsPolymorphicReferenceType())
             {
                 TypeVariableReference mutabilityType = typeVariableSet.CreateTypeVariableReferenceFromNIType(type.GetReferenceMutabilityType(), genericTypeParameters);
                 return(typeVariableSet.CreateReferenceToPolymorphicReferenceType(mutabilityType, referentType, lifetimeType));
             }
             return(typeVariableSet.CreateReferenceToReferenceType(type.IsMutableReferenceType(), referentType, lifetimeType));
         }
         string constructorTypeName   = type.GetName();
         var    constructorParameters = type.GetGenericParameters();
         if (constructorParameters.Count == 1)
         {
             TypeVariableReference parameterType = typeVariableSet.CreateTypeVariableReferenceFromNIType(constructorParameters.ElementAt(0), genericTypeParameters);
             return(typeVariableSet.CreateReferenceToConstructorType(constructorTypeName, parameterType));
         }
         throw new NotImplementedException();
     }
 }