Exportar (0) Imprimir
Expandir Tudo
Expandir Minimizar
Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações.
Tradução
Original

Método TypeBuilder.MakeGenericType

Substitutes the elements of an array of types for the type parameters of the current generic type definition, and returns the resulting constructed type.

Namespace:  System.Reflection.Emit
Assembly:  mscorlib (em mscorlib.dll)

public override Type MakeGenericType(
	params Type[] typeArguments
)

Parâmetros

typeArguments
Tipo: System.Type[]
An array of types to be substituted for the type parameters of the current generic type definition.

Valor de retorno

Tipo: System.Type
A Type representing the constructed type formed by substituting the elements of typeArguments for the type parameters of the current generic type.

ExceçãoCondição
InvalidOperationException

The current type does not represent the definition of a generic type. That is, IsGenericTypeDefinition returns false.

ArgumentNullException

typeArguments is null.

-or-

Any element of typeArguments is null.

ArgumentException

The number of elements in typeArguments is not the same as the number of type parameters in the current generic type definition.

-or-

Any element of typeArguments does not satisfy the constraints specified for the corresponding type parameter of the current generic type.

Use this method when your emitted code requires a type constructed from the current generic type definition. It is not necessary to call the CreateType method before calling the MakeGenericType method on a TypeBuilder that represents a generic type definition. If the current TypeBuilder does not represent the definition of a generic type, an InvalidOperationException is thrown.

The object returned by this method functions as a placeholder for a constructed generic type in your emitted code. It is an instance of a class derived from Type that has limited capabilities. In particular:

  • To get methods, fields, and constructors for these constructed generic types, use the GetMethod(Type, MethodInfo), GetField(Type, FieldInfo), and GetConstructor(Type, ConstructorInfo) method overloads.

  • Two instances that represent the same constructed type do not compare as equal. For example, in the following code t1.Equals(t2) returns false:

    Dim t1 As Type = tbldr.MakeGenericType(GetType(String))
    Dim t2 As Type = tbldr.MakeGenericType(GetType(String))
    Dim result As Boolean = t1.Equals(t2)
    

    Type t1 = tbldr.MakeGenericType(typeof(string));
    Type t2 = tbldr.MakeGenericType(typeof(string));
    bool result = t1.Equals(t2);
    

    Type^ t1 = tbldr->MakeGenericType(String::typeid);
    Type^ t2 = tbldr->MakeGenericType(String::typeid);
    bool result = t1->Equals(t2);
    

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

o.NET Framework e.NET Compact Framework não oferecem suporte a todas as versões de cada plataforma. Para obter uma lista de versões suportadas, consulte Requisitos de sistema do .NET framework.

.NET Framework

Compatível com: 3.5, 3.0, 2.0

Contribuições da comunidade

ADICIONAR
Mostrar:
© 2014 Microsoft