TypeBuilder.MakeGenericType(Type[]) Метод

Определение

Заменяет элементы массива типов для параметров типа текущего определения универсального типа и возвращает результирующий созданный тип.

public:
 override Type ^ MakeGenericType(... cli::array <Type ^> ^ typeArguments);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")]
public override Type MakeGenericType(params Type[] typeArguments);
public override Type MakeGenericType(params Type[] typeArguments);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")]
public override Type MakeGenericType(params Type[] typeArguments);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")>]
override this.MakeGenericType : Type[] -> Type
override this.MakeGenericType : Type[] -> Type
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")>]
override this.MakeGenericType : Type[] -> Type
Public Overrides Function MakeGenericType (ParamArray typeArguments As Type()) As Type

Параметры

typeArguments
Type[]

Массив типов, заменяемых параметрами типа текущего определения универсального типа.

Возвращаемое значение

Представляет Type созданный тип, сформированный путем замены элементов typeArguments для параметров типа текущего универсального типа.

Атрибуты

Исключения

Текущий тип не представляет определение универсального типа. То есть IsGenericTypeDefinition возвращается false.

typeArguments равно null.

–или–

Любой typeArguments элемент is null.

Свойство Module любого элементаtypeArguments.null

–или–

Свойство Assembly модуля любого элементаtypeArguments.null

Комментарии

Используйте этот метод, если в созданном коде требуется тип, созданный из текущего определения универсального типа. Перед вызовом CreateType метода в объекте, MakeGenericType представляющего определение универсального типа, не нужно TypeBuilder вызывать метод. Если текущий TypeBuilder тип не представляет определение универсального типа, InvalidOperationException создается исключение.

Объект, возвращаемый этим методом, выполняется в качестве заполнителя для созданного универсального типа в созданном коде. Это экземпляр класса, производный от Type того, что имеет ограниченные возможности. В частности:

  • Чтобы получить методы, поля и конструкторы для этих созданных универсальных типов, используйте GetMethod(Type, MethodInfo)GetField(Type, FieldInfo)перегрузки методов и GetConstructor(Type, ConstructorInfo) методов.

  • Два экземпляра, представляющие тот же созданный тип, не сравниваются как равные. Например, в следующем коде t1.Equals(t2) возвращается false:

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

Применяется к