Ejemplo n.º 1
0
        public sealed override Type MakeGenericType(params Type[] instantiation)
        {
            if (instantiation == null)
            {
                throw new ArgumentNullException("instantiation");
            }

            if (!(this.InternalIsGenericTypeDefinition))
            {
                throw new InvalidOperationException(SR.Format(SR.Arg_NotGenericTypeDefinition, this));
            }

            // We intentionally don't validate the number of arguments or their suitability to the generic type's constraints.
            // In a pay-for-play world, this can cause needless MissingMetadataExceptions. There is no harm in creating
            // the Type object for an inconsistent generic type - no EEType will ever match it so any attempt to "invoke" it
            // will throw an exception.
            RuntimeType[] genericTypeArguments = new RuntimeType[instantiation.Length];
            for (int i = 0; i < instantiation.Length; i++)
            {
                genericTypeArguments[i] = instantiation[i] as RuntimeType;
                if (genericTypeArguments[i] == null)
                {
                    if (instantiation[i] == null)
                    {
                        throw new ArgumentNullException();
                    }
                    else
                    {
                        throw new PlatformNotSupportedException(SR.PlatformNotSupported_MakeGenericType); // "PlatformNotSupported" because on desktop, passing in a foreign type is allowed and creates a RefEmit.TypeBuilder
                    }
                }
            }
            return(ReflectionCoreNonPortable.GetConstructedGenericType(this, genericTypeArguments));
        }